Skip to Content
Nextra 4.0 is released 🎉
Control FlowConditionalsWhat are Conditionals?

What are Conditionals?

Conditionals let your program make decisions: run one block of code when something is true, and a different block when it’s false. In Python you build conditions using comparison operators (like ==, <, >=) and logical operators (and, or, not), then use them inside if statements (and later in loops).

What you’ll learn here

  • Comparison operators — Compare two values and get True or False (==, !=, <, >, <=, >=).
  • Logical operators — Combine conditions with and, or, and not.
  • If statements — Run code only when a condition is true, with else and elif for multiple cases.

Work through these in order: comparisons and logical operators give you the building blocks; if statements are where you use them.

Last updated on