Skip to content

Python “is not True” same as “is False”?

  • by

Python “is not True” and “is False” is not the same. x is not True will be true for any value x that is not the singleton object True.

is not is its own comparison operation.

The NOT operator ! negates logical expressions so that TRUE expressions become FALSE and FALSE expressions become TRUE.

Python “is not True” same as “is False”?

Simple example code disassembled bytecode, is not is its own comparison operation

import dis

print(dis.dis("x is not True"))
print(dis.dis("x is false"))

Output:

Python "is not True" same as "is False"?

Let’s illustrate this with an example:

x = False

print(x is not True)  # True, because x is False
print(x is False)     # True, because x is False

Both statements return True because x is indeed False. However, if x were some other non-True value:

x = 0

print(x is not True)  # True, because x is not True
print(x is False)     # False, because x is not False

In this case, the first statement evaluates to True because x is 0, not True. The second statement evaluates to False because x is not the Boolean False.

Note: IDE: PyCharm 2021.3.3 (Community Edition)

Windows 10

Python 3.10.1

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading