Skip to content
Justice Tech School

Booleans

Comparisons give True or False. Many values count as False when used in a condition: 0, 0.0, an empty string, an empty list, an empty dict and None. Everything else is True. bool() shows how a value is treated.

Example
print(5 > 3)
print(5 == 6)
print(bool(""), bool("a"))
print(bool([]), bool([0]))
name = ""
if not name:
    print("Name is empty")

Result

True
False
False True
False True
Name is empty

Exercise

Which value means true?

is_ok = 

Quiz Test

Which value counts as False in a condition?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.