Skip to main content
Course/Module 1/Topic 4 of 4Beginner

Conditionals (if/elif/else)

Make decisions in Python using if, elif, and else. Python uses indentation (spaces) instead of braces.

25 minBy Priygop TeamLast updated: Feb 2026

Python Conditionals

Python uses if, elif (else if), and else for decision making. Important: Python uses INDENTATION (4 spaces or 1 tab) to define code blocks — there are no curly braces {}. Getting indentation wrong causes an IndentationError. This is one of Python's most distinctive features.

Conditional Rules

  • if condition: — Runs if condition is True
  • elif condition: — Checks another condition (else if)
  • else: — Runs if all conditions are False
  • Indentation is MANDATORY — use 4 spaces
  • No parentheses needed around conditions
  • No curly braces — indentation defines the block
  • Comparison: ==, !=, >, <, >=, <=

Conditionals Example

Example
age = 18

# Basic if/else
if age >= 18:
    print("You are an adult.")
else:
    print("You are a minor.")

# elif chain
score = 75
if score >= 90:
    print("Grade: A")
elif score >= 80:
    print("Grade: B")
elif score >= 70:
    print("Grade: C")
else:
    print("Grade: F")

# Check even or odd
number = 7
if number % 2 == 0:
    print(f"{number} is Even")
else:
    print(f"{number} is Odd")

Try It Yourself: Grade Calculator

Try It Yourself: Grade CalculatorPython
Python Editor
✓ ValidTab = 2 spaces
Python|26 lines|528 chars|✓ Valid syntax
UTF-8

Quick Quiz

Chat on WhatsApp
Priygop - Leading Professional Development Platform | Expert Courses & Interview Prep