我的程序中有两个布尔变量,分别叫做after和late。只是为了确保每个变量有正确的值,我测试了每一个与下面的命令:为什么表达式是真实的和真实的? (python 2.7)
print(after)
print(late)
该程序打印
false
true
预期。然而,当我运行下面的代码:
if after and late:
print('true and true')
elif after and (not late):
print('true and false')
elif (not after) and late:
print('false and true')
elif (not after) and (not late):
print('false and false')
程序打印
'true and true'
这意味着表达后,晚正在评估为true。为什么这种评估是真实的,即使真假都会产生错误?
''后''和'后'的字符串,也许? – nneonneo 2014-12-04 04:45:50
更多的代码片段将会有所帮助 – Codeek 2014-12-04 04:47:46
它们绝对不是布尔值。检查案件。 Python的布尔值是大写字母。 – dyoo 2014-12-04 04:51:03