Booleans
A boolean has only two answers.
True or False. Yes or no. Light on or light off.
Booleans help computers make choices.
In Python the words are True and False with capital first letters.
Making booleans
You can write True or False yourself.
Or you can ask a question that gives True or False.
Comparisons make booleans
Compare two values. Python answers True or False.
== equal
!= not equal
< less than
> greater than
<= less or equal
>= greater or equal
Using booleans in if
if looks at a boolean.
If it is True, the indented block runs.
If it is False, that block is skipped.
not flips the answer
not turns True into False, and False into True.
Like flipping a light switch.
Truthy and falsy again
Python can treat other values like booleans in if.
Empty things act like False. Filled things often act like True.
bool() helper
Use bool() to see how Python scores a value.
Tip: Write True and False with capital T and F. Lowercase will not work.
Test yourself
Three quick questions made just for this lesson. Earn 10 XP per correct answer.