In the Python console:
>>> a = 0 >>> if a: ... print "L" ... >>> a = 1 >>> if a: ... print "L" ... L >>> a = 2 >>> if a: ... print "L" ... L
Why does this happen?
In Python, bool is a subclass of int, and False has the value 0; even if values weren't implicitly cast to bool in an if statement (which they are), False == 0 is true.
bool
int
False
0
if
False == 0
1.4m articles
1.4m replys
5 comments
57.0k users