【发布时间】:2015-02-04 01:43:38
【问题描述】:
我试图用hh:mm 来表达时间。我知道冒号告诉 python 从小时数到分钟数,但这不是我想要的。有人能解释一下纠正我这个错误的方法吗?
def extract_hours(hours:minutes):
"""returns an integer representing the number of hours number, number -> number"""
return (hours)
这是我得到的错误:
NameError: name 'minutes' is not defined
【问题讨论】:
-
你提议的函数是如何调用的?您似乎在尝试说
def hr(tm:'hours:minutes'): return int(tm.split(':')[0]) -
是的,我必须将格式保持为“小时:分钟”,我尝试了您的解决方案,但它给了我冒号的语法错误...?
标签: python function python-3.x annotations