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"?

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

Your email address will not be published. Required fields are marked *