Python by example

Boolean in Python

The boolean represents the truth values True and False. They are used to evaluate conditions in control structures such as if statements and loops.

is_true = True
is_false = False

Logical operations can be performed on boolean values in Python, such as and, or, and not:

# AND
result = True and False
print(result) # Output: False

# OR
result = True or False
print(result) # Output: True

# NOT
result = not True
print(result) # Output: False
Next example: Variables