Skip to content
Laviyx Learn

Try

Python course menu

Python pass Statement: A Placeholder That Does Nothing

Learn the Python pass statement: why Python needs a placeholder for empty blocks, using pass in functions, classes, loops and conditions, the ... (Ellipsis) alternative, and how pass differs from continue and break.

Beginner5 min readUpdated
On this page

pass is a statement that does nothing. That sounds pointless, but Python's syntax requires every block (after if, for, def, class, …) to contain at least one statement. pass fills that space when you have nothing to put there yet.

Why Python needs it#

An empty block is a syntax error:

Python
def todo():
print("after")
Output
  File "example.py", line 2
    print("after")
    ^^^^^
IndentationError: expected an indented block after function definition on line 1

pass as a placeholder#

Sketch the structure of a program first, and fill in the details later:

Python
def calculate_tax(amount):
    pass

print(calculate_tax(100))
Output
None

The function exists and can be called; it just does nothing yet, so it returns None.

In a class#

An empty class is useful as a starting point, or as a simple custom exception:

Python
class Invoice:
    pass

inv = Invoice()
print(type(inv).__name__)
Output
Invoice

In conditions#

Sometimes one branch genuinely needs no action, but writing it out makes the logic clearer:

Python
value = 5
if value > 0:
    pass  # TODO: handle positive values
else:
    print("not positive")
print("end")
Output
end

A # TODO comment next to pass reminds you, and others, that the block is unfinished.

In loops#

pass inside a loop does nothing on each iteration, but the loop still runs completely:

Python
for n in range(3):
    pass
print("loop finished, n =", n)
Output
loop finished, n = 2

pass vs continue vs break#

StatementIn a loop it…
passdoes nothing; the rest of the iteration still runs
continueskips the rest of this iteration
breakends the whole loop

The Ellipsis alternative#

You will also see ... (three dots, called Ellipsis) used as a placeholder, especially in type stubs and documentation:

Python
def f():
    ...

print(f())
Output
None

Both work. pass is the traditional choice in regular code.

Common mistakes#

Practice#

Practice exercise

Sketch a small program structure with three empty functions: load_data(), clean_data(data) and save_report(data). Call all three in order without errors.

Show hint

Each function body is just pass. Calling a function that only contains pass returns None.

Show solution
Python
def load_data():
    pass  # TODO: read the CSV file

def clean_data(data):
    pass  # TODO: remove empty rows

def save_report(data):
    pass  # TODO: write the summary

data = load_data()
data = clean_data(data)
save_report(data)
print("Pipeline ran")
Output
Pipeline ran

This "skeleton first" approach lets you check the overall flow before writing each part.

Key takeaway#

Finished this lesson?