我正在尝试让 day 打印 true 或 false。目前,无论给出“日期”的整数是多少,它都只打印 False 。我是 Python 的新手,所以如果这是新手的疏忽,请多多包涵。
def date():
date = raw_input("Date (ex. Jun 19): ")
date = date.split(' ')
month = date[0]
month = month[:3].title()
day = date[1]
day.isdigit()
if day < 10:
print "True"
else:
print "False"
请您参考如下方法:
day 是一个字符串,在 Python 2 中,any string compares greater than any number .
>>> "0" > 1
True
>>> "" > 100000000000000000000
True
这种(一致但任意的)行为在 Python 3 中已经改变:
>>> "" > 100000000000000000000
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unorderable types: str() > int()
