Python if-elif-else

Python uses indentation (normally 4 spaces) to mark a block. A colon : ends each condition line.

Python
marks = 82
if marks >= 90:
    grade = "A+"
elif marks >= 75:
    grade = "A"
elif marks >= 60:
    grade = "B"
else:
    grade = "C"
print("Grade:", grade)
Grade: A

Conditional Expression

Python
n = 7
print("even" if n % 2 == 0 else "odd")
odd

match-case (Python 3.10+)

Python
cmd = "stop"
match cmd:
    case "start":
        print("Starting")
    case "stop":
        print("Stopping")
    case _:
        print("Unknown")
Stopping
Track your progress through the Python course