28 FIRST STEPS
Making decisions Err...
Every day you make decisions about what to do Am I a
horse?
next, based on the answers to questions you ask
yourself. For example, “Is it raining?”, “Have I done
my homework?”, “Am I a horse?” Computers also
make decisions by asking questions.
Questions that compare
Are you sure you The questions that computers ask themselves usually
want to do that?
involve comparing one thing with another. For example,
a computer might ask if one number is bigger than
another. If it is, the computer might then decide to
run a block of code that would otherwise be skipped.
▷ Boolean values Variable
The answers to the questions computers ask
have only two possible values: True or False. >>> answer_one = True
Python calls these two values Boolean values, >>> answer_two = False
and they must always start with a capital letter.
You can store a Boolean value in a variable.
Boolean value
EXPERT TIPS ▽ Logical operators
Equals signs These symbols tell computers to make
comparisons. Programmers call them
In Python, you can use a single equals sign, =, or a double logical operators. You may have used
some of them in math. The words “and”
equals sign, ==. They mean slightly different things. Use
and ”or” can also be used as logical
a single equals sign when you want to set the value of a
operators in computer code.
variable. Typing age = 10, for example, sets the value of
the variable age to 10. Use a double equals sign when
you want to compare two values, as in the example below. Symbol Meaning
== equal to
This sets the value of the variable. != not equal to
< less than
>>> age = 10 > greater than
This compares your
>>> if age == 10: age with the variable.
print('You are ten years old.')
I'm greater
than you!
The code prints the message if the two match.