MicrolearnENPTES

if and else

Lesson 6 of 20 · Py.Micro

Run a block only when a condition is true, otherwise run another.

if runs a block when the condition is True

After if condition: come the indented lines that run only when the condition is true. Watch the step by step: line 3 is skipped when the temperature is low.

Check yourself

How does Python know which lines belong to an if?

Do it in the browser: a real Python tool, a short mission and instant feedback. No install.

Start this lesson — free
← True or FalseMany cases with elif →

All lessons · Py.Micro