This Python Booleans lesson is for a beginner. Read the short notes, run each example, then change one name or number and run it again.
True and False are the two boolean values. Comparisons such as ==, !=, <, and >= produce them.
Empty text, 0, None, and an empty list are treated as false in an if test. Most other values are treated as true.
Example 1: Start here
Use == to compare. A single = assigns and does not belong in a condition.
score = 75 # a whole number
print(score >= 70) # a comparison is True or False
print(bool("")) # 0 is False; any other number is True
print(bool("Meera")) # 0 is False; any other number is True
Example 2: Compare numbers
A comparison produces True or False.
print(82 >= 80) # a comparison is True or False
print(70 >= 80) # a comparison is True or False
Example 3: Combine tests
and is True only when both tests pass.
score = 82 # a whole number
print(score >= 80 and score < 100) # and needs both tests; or needs one
Example 4: Flip a value
not turns True into False and False into True.
open_batch = True # True or False, not text
print(not open_batch) # not flips True and False
