If / Else

Making Decisions with If/Else

Conditional statements let your program make decisions. The if statement checks a condition and runs code only if the condition is True.
python
age = 18

if age >= 18:
    print("You can vote!")
else:
    print("Too young to vote")

Elif (Else If)

Use elif to check multiple conditions. Python checks each condition from top to bottom and runs the first one that's True.
python
score = 85

if score >= 90:
    grade = "A"
elif score >= 80:
    grade = "B"
elif score >= 70:
    grade = "C"
else:
    grade = "F"

print(f"Grade: {grade}")

Tip:Python uses indentation (4 spaces) to define code blocks instead of curly braces. This makes Python code naturally clean and readable!

PlaygroundPython
Output
Click "Run" to see output

💬 Got questions? Ask me anything!