Basic if
age = 20
if age >= 18:
print("You are an adult")
if-else
age = 15
if age >= 18:
print("You are an adult")
else:
print("You are a minor")
if-elif-else
score = 85
if score >= 90:
grade = "A"
elif score >= 80:
grade = "B"
elif score >= 70:
grade = "C"
else:
grade = "F"
print(grade) # "B"
Multiple conditions
age = 25
has_license = True
if age >= 18 and has_license:
print("Can drive")
if age < 18 or age > 65:
print("Special category")
if not has_license:
print("No license")
Nested if
age = 20
has_license = True
if age >= 18:
if has_license:
print("Can drive")
else:
print("Need license")
else:
print("Too young")
Ternary operator
Short form for simple if-else:
age = 20
status = "adult" if age >= 18 else "minor"
print(status) # "adult"