Home Tutorials Python Tutorial Booleans
Booleans

Booleans


Definition: Boolean values represent one of two values: True or False. They are used to represent the truth value of an expression.

Why: Booleans are essential for decision-making in programming. They are used in conditions and comparisons to control the flow of the program based on whether a statement is true or false.

Syntax

is_active = True
is_expired = False

Example

x = 10
print(x > 5)  # Output: True
print(x < 3)  # Output: False

Explanation

  • The expression x > 5 is evaluated. Since 10 is greater than 5, the result is True.
  • The expression x < 3 is evaluated. Since 10 is not less than 3, the result is False.

Key Notes

  • In Python, Boolean values must always start with a capital letter: True and False.
  • Many expressions in Python evaluate to a Boolean, especially those using comparison operators (like ==, >, or <).
  • Almost any value can be evaluated as a Boolean; for example, most non-zero numbers are True, while 0 and empty strings are False.
Example

🏋️ Test Yourself With Exercises

Take our quiz on Booleans to test your knowledge.

Exercise »