Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 1.4 — True, False and None
Python · Example 3 of 3

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.

01

Set x = 0 and y = None. Print bool(x) and bool(y), and then x is None and y is None.

02

Set a = 3, b = 0, c = 7 and print how many of them are non-zero by adding up bool() values.

03

Store the result of print("hi") in a variable and print the variable. Say what it shows.

Explain it without notes

01

Which values are falsy in Python? Give at least five.

02

Why should you test x is None and not x == None?

03

What is the relationship between bool and int?

04

Why does bool("False") return True?

A form payload: 0, None and the word "False"
Sign in to run this example in your browser.

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]