Python: True, False

By Xah Lee. Date: . Last updated: .

In Python:

Following evaluates to False:

# python 3

# all the following are True

if True:
    print(True)

if 3:
    print(True)

if "abc":
    print(True)

# all the following are False

if False:
    print(True)

if None:
    print(True)

if []:
    print(True)

if 0:
    print(True)

if "":
    print(True)

Boolean Operators

not x
not
x == y
equal
x != y
not equal
x < y
less than
x <= y
less equal
x > y
greater
x >= y
greater equal
x is y
same object
x is not y
not same object

Python

Regex

Text Processing

Web

Misc