Module 2
Questions with True and False
Programs can answer yes-or-no questions.
Yes or no
Programs often need to answer yes-or-no questions. Is the temperature too high? Is the sequence valid? Does the sample match? Python represents yes and no with two special values: True and False.
Python
print(5 > 3) print(5 < 3)
→ True
False
The expression 5 > 3 asks: is 5 greater than 3? Python answers True. The expression 5 < 3 asks: is 5 less than 3? Python answers False.
Remember
True and False are called booleans. They are a type of data, just like strings and numbers. Notice: no quotes around them.
What does print(10 > 5) display?