Exit
  1. Learn
  2. Check
  3. Solve
  4. Reflect

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.

A comparison: asks a question and answers true or false.
In code
age = 20
adult = age >= 18      # True
Can we afford it?
money: 50
0
price: 30
1
enough: ?
2
line
money
50
price
30

money holds 50 and price holds 30.

Move 1 of 4

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.

One equals sign: puts a value in. Two equals signs ask a question.
In code
enough = money >= price
same = money == price