Questions with yes-or-no answers
Not every value is a number. Some answer a question with just two possibilities: true or false. We call these booleans.
You get one by comparing two values. Is the age at least 18? Is the price more than the money in your pocket? The comparison words are: bigger than, smaller than, at least, at most, the same as, and different from. Each one gives back true or false.
age = 20 adult = age >= 18 # True
- money
- 50
- price
- 30
money holds 50 and price holds 30.
Keep the answer
A true-or-false answer can sit in a box like any other value. You can store it, pass it on, or give it back as the result of your function.
One warning: a single equals sign puts a value into a box. To ask whether two values are the same, you use two equals signs. Mixing them up is one of the most common beginner mistakes, so read each line carefully.
enough = money >= price same = money == price