Python: Boolean. True False

By Xah Lee. Date: . Last updated: .

Literal value for true and false

True and False are literal values of boolean type.

print(type(True))  # <class 'bool'>
print(type(False))  # <class 'bool'>

What value evaluates to true

In a if statement,

Following evaluates to False:

Convert to true false

You can use the function bool to test.

# all the following are True

print(bool(3))
print(bool("abc"))

# all the following are False

print(bool(None))
print(bool([]))
print(bool(0))
print(bool(""))