Python evaluates 0 to False
0 - false value in python
False values: from (2.7) documentation:
zero of any number type, for example, 0, 0L, 0.0, 0j.
Everything inside the if clause implicitly calls bool . Thus,
if 1: ... really:
if bool(1): ... and bool calls __nonzero__ 1 which indicates whether the object is True or False
Demo:
class foo(object): def __init__(self,val): self.val = val def __nonzero__(self): print "here" return bool(self.val) a = foo(1) bool(a) #prints "here" if a: #prints "here" print "L" #prints "L" since bool(1) is True. 1 __bool__ in python3.x