New: Complete Beginner's Guide to Coding is now available in Premium
Updated: Indian Govt Exam roadmaps now include salary breakdowns & timelines
Tip: Use the Career Hub to explore all career paths in one place
Tutorials Python Python If/Else

Python If/Else

Python

Python uses if, elif, and else for decisions. Indentation (spaces) is mandatory!

Important

  • Python uses elif (not "else if")
  • Indentation (4 spaces) defines code blocks — no curly braces!
  • Use == for comparison, = for assignment
Example — PYTHON
# Simple condition
age = 18
if age >= 18:
    print("You can vote! ✅")
else:
    print("Too young ❌")

# Multiple conditions
marks = 85
if marks >= 90:
    print("Grade: A+")
elif marks >= 75:
    print("Grade: A")
elif marks >= 60:
    print("Grade: B")
else:
    print("Grade: C")

# One-liner
status = "Adult" if age >= 18 else "Minor"
print(status)
Result
You can vote! ✅
Grade: A
Adult