The table below shows what values are considered equal in the python programming language. I thought I might be able to find more reasons for Why I hate Python, but actually the python truth table is very reasonable. Also, This truth table will help you be confident of what values are considered True or False.
This table demonstrates why it is best practice to use x is None
instead of if x == None
. None can be equal to any object instance depending on its implementation of __eq__
.

This is a pure and beautiful sight compared to to Javascript or PHP. It is a little surprising to me that [] == []
since I would expect them to be two different list instances, but I would expect equality for (,) = (,)
(identical tuples).
There are a few nuances when considering truthiness, however. If you’ve got code that reads if x: ...
The following values for x are treated as false:
None
False
- zero of any numeric type. Like these:
0
,0L
,0.0
,0j
. - any empty string, tuple, or array.
''
,()
,[]
. - an empty dictionary, for example,
{}
. - instances of user-defined classes, if the class defines a
__nonzero__()
or__len__()
method and that method returns the integer0
or boolean valueFalse
Everything else is truthy (considered equal to True).

Here’s the code I used to generate the tables above.