TensorLearn
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
python
name = "" if not name: print("Name is empty") # This runs

The Match Statement (Python 3.10+)

A powerful upgrade to the classic switch statement.

python
status = 404 match status: case 200: print("OK") case 404: print("Not Found") case _: print("Unknown")

While vs For

  • Use for when you know the collection or range.
  • Use while when you are waiting for a condition (e.g., "while user has not quit").

Mark as Completed

TensorLearn - AI Engineering for Professionals