def is_after1(t1, t2):
"""true if t1 follows t2 chronologically"""
if t1.hour > t2.hour:
return True
elif t1.hour == t2.hour:
if t1.minute > t2.minute:
return True
elif t1.hour == t2.hour and t1.minute == t2.minute:
if t1.second > t2.second:
return True
else:
return False
因此,我尝试在比较后运行一个is廑u,将time作为类“time()”的对象。 但是,当我运行函数时,什么也没有发生。以下是我的函数以及“time”和“time1”的相关值:
^{pr2}$
您应该打印返回值或将其分配给某个变量,否则返回值将被丢弃。在
或者:
^{pr2}$您确实想通过实现special Python hook methods,将您的
is_after
方法合并到类本身来定义Time()
类型的实例如何进行比较。在一个^{} method 将告诉Python两个对象是如何相等的,您可以使用^{} 、^{} 、^{} 和{a6}钩子来定义排序比较。在
使用^{} class decorator 最小化需要实现的方法数:
现在您只需使用Python}运算符直接比较
^{pr2}$<
、<=
、>
、>=
和{Time()
实例:相关问题 更多 >
编程相关推荐