Check out the section in python documentation on truth value testing
https://docs.python.org/3/library/stdtypes.html
Reproducing some of the documentation
Truth Value Testing
Any object can be tested for truth value, for use in an if or while condition or as operand of the Boolean operations below.
By default, an object is considered true unless its class defines either a __bool__()
method that returns False or a __len__()
method that returns zero, when called with the object. Here are most of the built-in objects considered false:
constants defined to be false: None and False.
zero of any numeric type: 0, 0.0, 0j, Decimal(0), Fraction(0, 1)
empty sequences and collections: '', (), [], {}, set(), range(0)
Operations and built-in functions that have a Boolean result always return 0 or False for false and 1 or True for true, unless otherwise stated. (Important exception: the Boolean operations or and and always return one of their operands.)
if z or z1 == 0:
is testing if z
a numeric type any value other than 0
is evaluated to true.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…