CurriculumPython if, elif and else for Kidsif, by itself
The Python if Statement Explained for Beginners
Doing something only when a question is True — and nothing when it isn't.
if, by itself
Now you can ask a question. Let's actually DO something based on the answer.
if CONDITION: means 'the next line only runs when this is True'.
health = 20
if health < 30:
print("Watch out!")Output
Watch out!See the indent? Everything indented under the if belongs to it — that's how Python knows what's conditional.
if health < 30:
print("Watch out!")And here's the important part: if the condition is False, absolutely nothing happens. That's normal.
health = 90
if health < 30:
print("Watch out!")No else needed. An if all by itself, doing nothing when it's False, is completely correct.
Check your understanding
health = 90. What happens here?
health = 90
if health < 30:
print("Watch out!")
print("Done checking.")Why: health is 90, so health < 30 is False. The indented print never runs, and Python moves straight to the next line: Done checking. No else, no error — this is exactly how if is meant to work alone.
What you'll practice
If the dragon's health drops below 30, it should growl a warning. Its health is 20 — make it growl.
More from this topic
if, by itself is one lesson inside Python if, elif and else for Kids — see the full lesson order and what the whole topic covers.
View the full topic →