bool is an int, and truthiness
Predict each line of the bool() group first. Which surprised you?
A bool is either True or False, the answer to a yes-or-no question. None is Python's way of saying "no value here". Every value also has a truthiness: empty and zero values count as false, nearly everything else as true.
Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.
Ready for more? This phase has 6 hands-on exercises with automatic checks.
Practice questions
Write the code in the editor, run it, then open the model answer to compare.
Set x = 0 and y = None. Print bool(x) and bool(y), and then x is None and y is None.
Set a = 3, b = 0, c = 7 and print how many of them are non-zero by adding up bool() values.
Store the result of print("hi") in a variable and print the variable. Say what it shows.
Explain it without notes
Which values are falsy in Python? Give at least five.
Why should you test x is None and not x == None?
What is the relationship between bool and int?
Why does bool("False") return True?
Expected output
2 10
True
<class 'bool'> <class 'NoneType'>
False True True False
False True True
False True
False