Making decisions in Python

Module 3 · Making decisions in Python · Lesson 1 of 7

Questions and answers

Real programs don't just plough straight ahead — they decide. Is the password correct? Is the basket empty? Did the player win? Every decision starts the same way: with a yes/no question.

Ask a question, get True or False
7 > 3?True
2 > 5?False

In Python, you ask such a question with a comparison, and the answer comes back as one of the two boolean values you already met: True or False. “Is 7 greater than 3?” — True. “Is 2 greater than 5?” — False.

Run it yourselfruns in your browser · Python
main.py

That's the raw material of every decision. Next we'll meet the full set of operators for asking these questions — then use the answers to actually change what your program does.