Boolean logic

In Python (and in many programming languages), we can use these values:

true = True  
false = False

Conditions (such as comparisons between numbers) return a boolean value:

print(5 > 3) # True
print(2 == 4) # False

Main logical operators

There are three fundamental logical operators in Boolean logic:

  • AND (and): All conditions must be true
    Example: True and False → False
  • OR (or): At least one condition must be true
    Example: True or False → True
  • NOT (not): Reverses the value (true becomes false, and vice versa)
    Example: not True → False

Practical examples

a = 5  
b = 10  

print(a > 0 and b < 20)   # True  
print(a > 0 or b > 100)   # True  
print(not (a > 3))        # False

Where is Boolean logic used?

  • In programs, to make choices (if/else)
  • In search engines, to combine keywords
  • In electronic circuits, to turn components on or off
  • In games, to decide what happens if a player wins or loses

Exercise

Try to say if these expressions are True or False:

7 > 3 and 2 == 2   → _______  
10 < 5 or 3 > 1    → _______  
not (4 <= 4)       → _______