Skip to content
dreamcode
dreamcode
Back to map
If & Else · Lesson 4 of 44
+15 XP on finish
PYTHON BASICS

Branching paths

An if statement runs a block of code only if a condition is True. An optional else block runs instead if the condition is False. Indent the code inside each block using spaces.

How it reads
if sky == "clear": checks if the variable matches "clear"
The indented lines run only if their corresponding condition is met
else: captures any case where the condition was False
Cloud tip: Python uses indentation (4 spaces) to group blocks of code. Always make sure your indentation matches.
main.py
PYTHON
real Python, runs in your browser
CONSOLE
- run your code to see output -