Python最佳实践:assert command()== False [英] Best practice for Python: assert command() == False
本文介绍了Python最佳实践:assert command()== False的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道哪种更好/最好:
I wonder what is better/best:
>>> def command():
... return False
...
>>> assert command() == False
>>> assert command() is False
>>> assert not command()
干杯,马库斯
推荐答案
第三个是pythonic最多的.等效于:
The most pythonic is the third. It is equivalent to:
assert bool(command()) != False
这篇关于Python最佳实践:assert command()== False的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文