Python2
https://docs.python.org/2/reference/datamodel.html#object.__nonzero__object.__nonzero__(self)
Called to implement truth value testing and the built-in operation bool(); should return False or True, or their integer equivalents 0 or 1. When this method is not defined, __len__() is called, if it is defined, and the object is considered true if its result is nonzero. If a class defines neither __len__() nor __nonzero__(), all its instances are considered true.
Python3
https://docs.python.org/3.1/reference/datamodel.html#object.__bool__object.__bool__(self)
Called to implement truth value testing and the built-in operation bool(); should return False or True. When this method is not defined, __len__() is called, if it is defined, and the object is considered true if its result is nonzero. If a class defines neither __len__() nor __bool__(), all its instances are considered true.
如果要判断元素空,比如一个 list ,用 len(l)
如果要判断元素为 None, 用 is None