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
 ==  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:
- zero of any numeric type. Like these:
- any empty string, tuple, or array.
- an empty dictionary, for example,
- instances of user-defined classes, if the class defines a
__len__()method and that method returns the integer
0or boolean value
Everything else is truthy (considered equal to True).
Here’s the code I used to generate the tables above.
In your second table, I think the four values immediately below “False” should be the strings “1”, “0”, “-1” and “”.
In fact, that goes for both tables!
John – great catch, you are correct! “1”, “0”, “-1” are truthy while “” (the empty string) is falsey.
I kind of did a short analysis of the graph which seems, weird, or at least has weird choices of values to test for …