Skip to content
Justice Tech School

if, elif and else

Python uses indentation for blocks. elif adds more checks and else is the fallback. A conditional expression fits on one line.

Example
n = 15
if n % 15 == 0:
    print("FizzBuzz")
elif n % 3 == 0:
    print("Fizz")
else:
    print(n)
print("big" if n > 10 else "small")

Result

FizzBuzz
big

Exercise

Else if keyword.

 n > 5:

Quiz Test

What marks a block in Python?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.