Differentiate False and 0

To tell the difference between False and 0 you may use is to compare them. False is a singleton value and always refers to the same object. To compare all the items in a list to make sure they are not False, try:

all(x is not False for x in a_list)

BTW, Python doesn't cast anything here: Booleans are a subclass of integers, and False is literally equal to 0, no conversion required.


You would want to use is instead of == when comparing.

y = 0
print y == False # True
print y is False # False

x = False
print x == False # True
print x is False # True