Back to Course
Python Essentials: The Engineering Approach
Module 4 of 20
4. Flow Control
Truthy and Falsy
Booleans are True and False. But every object in Python decides if it is "Truth-like" or "False-like".
Falsy Values:
0,0.0""(Empty String)[],{},()(Empty Containers)None
pythonname = "" if not name: print("Name is empty") # This runs
The Match Statement (Python 3.10+)
A powerful upgrade to the classic switch statement.
pythonstatus = 404 match status: case 200: print("OK") case 404: print("Not Found") case _: print("Unknown")
While vs For
- Use
forwhen you know the collection or range. - Use
whilewhen you are waiting for a condition (e.g., "while user has not quit").