0
0
Pythonprogramming~5 mins

Truthy and falsy values in Python - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does it mean when a value is truthy in Python?
A truthy value is any value that Python treats as True when used in a condition, like in an if statement. For example, non-zero numbers and non-empty strings are truthy.
Click to reveal answer
beginner
What is a falsy value in Python?
A falsy value is any value that Python treats as False in a condition. Examples include 0, '' (empty string), [] (empty list), None, and False itself.
Click to reveal answer
beginner
Which of these values is falsy in Python? <br> A) 1 <br> B) '' <br> C) 'False' <br> D) [1, 2]
The correct answer is B) ''. An empty string is falsy. The others are truthy because 1 is non-zero, 'False' is a non-empty string, and [1, 2] is a non-empty list.
Click to reveal answer
intermediate
How does Python decide if a value is truthy or falsy in an if statement?
Python uses the built-in bool() function internally to check the truthiness of a value. If bool(value) returns True, the value is truthy; if it returns False, the value is falsy.
Click to reveal answer
beginner
Give two examples of truthy and two examples of falsy values in Python.
Truthy examples: 42 (non-zero number), 'hello' (non-empty string).<br>Falsy examples: 0 (zero), [] (empty list).
Click to reveal answer
Which of the following is considered falsy in Python?
A''
B1
C'False'
D[0]
What does Python use internally to check if a value is truthy or falsy?
Aint()
Bbool()
Cfloat()
Dstr()
Which of these values is truthy?
AFalse
BNone
C[1, 2, 3]
D0
Is the number -5 truthy or falsy in Python?
ANone of the above
BFalsy
CDepends on context
DTruthy
Which of these is NOT a falsy value in Python?
A' ' (a space)
B[]
C0.0
DNone
Explain what truthy and falsy values are in Python and give examples of each.
Think about how Python treats values in conditions like if statements.
You got /4 concepts.
    How does Python determine if a value is truthy or falsy when used in a condition?
    Consider what happens inside an if statement.
    You got /3 concepts.