Skip to content
Skip to resources
peazit

What do you want to understand today?

PEAZIT Aha card

A condition: the program chooses a branch

Go straight to resources ↓

if tests a condition. If true, its indented block runs; otherwise the else block runs. The operator == compares values, whereas = assigns a value.

A condition: the program chooses a branch
ObservationWhat it means
x = 7; x >= 5True: if branch
x = 3; x >= 5False: else branch

One worked example

  1. x = 7The variable holds 7.
  2. if x >= 5: y = 10 else: y = 207 >= 5 is true.
  3. y = 10Only the if branch runs.

Watch out: Indentation is structural in Python. Separate if blocks can run several branches; this if/else selects one.

Goal, prerequisites and card origin

What you will learn: Evaluate a simple Python if/else.

What you need first: Variables and numerical comparisons.

An original PEAZIT working card. Independent expert review and effectiveness testing have not yet taken place. · v1

Reference for the underlying principle ↗
Show connections

if tests a condition. If true, its indented block runs; otherwise the else block runs. The operator == compares values, whereas = assigns a value.

Other options for this topic

Catalogue

Find your own way. Resources open directly on their authors’ websites. Order reflects search relevance, not a teaching-quality rating.

47,636 resources to explore

15 independent sources

3 resource languages

EXPLORE / EN

Where will curiosity take you?

Start with a subject. Then find your way.

All topics
peazit

Everyone learns differently. Find your way.

Saved

For your next aha.

Your saved links stay in this browser.