🎓 A1Learner
🔍

Python Pass Statement

The pass statement is a statement that does nothing and fills an empty block. A program with pass in an unfinished block still runs.

An empty if with pass

The block is unfinished, but the program runs.

age = 20
if age >= 18:
    pass
print("Program runs")

Pass in the else branch

Maybe low scores need no action yet. pass keeps the branch legal.

score = 40
if score >= 50:
    print("Pass")
else:
    pass
print("Checked")

A comment alone is not enough

This code fails when you run it. The block holds only a comment, so Python raises an IndentationError.

age = 20
if age >= 18:
    # add the adult code later
print("Program runs")

A function skeleton (preview)

Functions come later in this course. This shows the shape only: pass holds the empty body.

def greet():
    pass

Example

choice = 2
print("Menu: 1 = play, 2 = scores, 3 = quit")
if choice == 1:
    pass
elif choice == 2:
    pass
else:
    pass
print("Menu ready. More code coming soon.")

Key points

  • pass is a statement that does nothing.
  • Python runs it and moves on.
  • Use pass as a placeholder.
  • It holds the place of code you will write later.
  • Any block can hold a pass.
  • A comment is not code.
  • A block with only a comment is still empty, and Python reports an error.
  • pass is real code, so it counts as the content of the block.

In this example, choice is 2. The first line prints the menu text. Python then tests choice against each branch in order. The choice 2 branch holds only pass, so nothing happens there yet. The last line still runs, and the skeleton program ends cleanly. You will meet it later inside loops, functions and classes too.

Note

Python ignores a comment completely.

Try it Yourself

Edit the code, then press Run.

Running is simulated · Python Playground

Exercise

Why do programmers write pass inside a block?