比如说定义了一个类FooBar,搞出了一个对象foobar
想要 not foobar == True。
想要 not foobar == True。
|
1
__nonzero__ 方法
http://www.rafekettler.com/magicmethods.html |
|
thedevil5032Aug 28, 2013 via iPad
3
If not foobar 就可以了,不用再 ==,参考的是 PEP8。
|
|
4
@thedevil5032 我只是表示一下,就是为了写你这种语句。
|
|
5
调试了半天没发现问题,原来因为Py3k 已经没有__nonzero__ 了 orz
__bool__ |