A form payload: 0, None and the word "False"
Realistic bugs: treating 0 as missing, trusting bool("False"), and assigning the result of list.sort(). The dictionary and list in it are taught in Phase 4; for now read them as a record and a list of values.
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
age given: True | age is falsy: True
nickname missing: True
bool of the word: True | parsed: False
3 4 0.75
{1: 'c'}
None [1, 2, 3]