我是 Python 的初学者,我在 YouTube 上看到了 Cory Schafer 关于布尔值和条件的教程。当他试图展示 Python 认为哪些值是 False 时,他有一个片段。他一一测试,但我想知道是否有更有效/更有趣的方法来做到这一点,所以我尝试提出这个 for 循环语句。我期望输出为 8 行 Evaluated to False,但我一直得到 Evaluated to True。有人可以启发我吗?谢谢!
condition = (False, None, 0, 0.00, '', (), [], {})
for i in condition:
if condition: # It is assumed that condition == true here, right?
print('Evaluated to True')
else:
print('Evaluated to False ')
#OUT:
Evaluated to True
Evaluated to True
Evaluated to True
Evaluated to True
Evaluated to True
Evaluated to True
Evaluated to True
Evaluated to …
Run Code Online (Sandbox Code Playgroud)