Page10/20
Control Flow & Loops · Page 1 of 2
If / Elif / Else
Control Flow & Loops
Making Decisions with if
Control flow allows your program to react differently based on conditions.
score = 85
if score >= 90:
grade = "A"
elif score >= 80:
grade = "B"
else:
grade = "C"
Truthy & Falsy Values
In Python, empty containers and zeros evaluate to False:
| Falsy | Truthy |
|---|---|
0, 0.0 | Any non-zero number |
"", [], {} | Non-empty string/list/dict |
None, False | Everything else |
data = []
if not data:
print("Data is empty!") # This will run
main.py
Loading...
OUTPUT
▶Click "Run Code" to execute…