我想知道什么是更好/最好的:
>>> def command():
... return False
...
>>> assert command() == False
>>> assert command() is False
>>> assert not command()
干杯,马库斯
可以在这里研究编码约定:Python 代码的 PEP 8 风格指南 http://python.org/dev/peps/pep-0008/#programming-recommendations
在那里你会发现:
不要使用 == 将布尔值与 True 或 False 进行比较
Yes: if greeting:
No: if greeting == True:
Worse: if greeting is True:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)