Lecture
Which values are always considered False?
Certain values like 0 and empty strings ("") are automatically considered False in conditional statements.
These values can be used to control program flow—for example, when the result of an arithmetic operation is 0.
Examples of values evaluated as False
a = 2 b = 3 if a - b: print("a - b is not 0.") else: print("a - b is 0.")
What values are always evaluated as False?
-
Numeric
0(integer0, float0.0) -
Empty string
"" -
Empty list
[], empty tuple(), empty dictionary{} -
None
Using conditionals
When these values are passed to an if statement, the condition is evaluated as False and the block of code does not execute.
Examples of values evaluated as False
if 0: print("This will not execute.") else: print("0 is evaluated as False.") if "": print("This will not execute.") else: print("An empty string is evaluated as False.")
Lessons in this chapter · Control Logical Flow with if, else, and elif
- 1. Controlling Program Flow with if Statements
- 2. The else Statement for When if Condition is False
- 3. Executing When One of Multiple Conditions is Met Using the elif Statement
- 4. Multiple-choice quiz
- 5. Which values are always considered False?
- 6. The `pass` Keyword That Does Nothing
- 7. Indicating Unimplemented Features with NotImplementedError
- 8. Coding Quiz - Python Temperature Converter
- 9. Multiple-choice quiz
- 10. Fill-in-the-blank quiz
Quiz
0 / 1
An empty list [] is evaluated as False in an if statement.
True
False
Lecture
AI Tutor
Design
Upload
Notes
Favorites
Help