Command Palette

Search for a command to run...

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

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.

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?

bool is an int, and truthiness
Sign in to run this example in your browser.

Expected output

2 10
True
<class 'bool'> <class 'NoneType'>
False True True False
False True True
False True
False