Understand how truthy and falsy values work in Python. Learn which values evaluate to True or False in conditional statements, with examples and practical tips for beginners.
In Python, some values are treated as True or False automatically when used in conditions.
False):NoneFalse0 (any numeric zero)"" (empty string)[] (empty list){} (empty dict)set() (empty set)username = ""
if username:
print("Welcome,", username)
else:
print("Please enter a valid username")
Since username is an empty string (""), it’s falsy — the else block runs.
score = 75
if score:
if score >= 90:
print("Grade A")
elif score >= 75:
print("Grade B")
else:
print("Grade C")
else:
print("No score provided")
Tutorials, Roadmaps, Bootcamps & Visualization Projects