An empty function body is invalid in Python, even when the function should do nothing for now. The pass statement gives the function body a statement without performing an operation.

I’ll show how pass keeps an empty function valid and explain why a comment alone cannot replace it.

TL;DR: Python pass does nothing

The pass statement performs no operation, but it gives a Python code block the statement its syntax requires. Use it when a valid function, class, or branch should intentionally have no behavior yet.

  • pass does not skip a loop iteration. Use continue for that.
  • A comment alone does not make an otherwise empty code block valid.
  • A function containing only pass returns None when called.

What is the pass statement in Python?

pass is a null operation, which means Python executes the statement and makes no change. A code block, also called a suite, is the indented body after a statement such as if or def. Python requires that body to contain a statement.

That makes pass useful for a deliberate empty branch or a temporary function or class definition. A comment can explain what is planned, but it is not a Python statement and cannot fill that required place.

The distinction is between syntax and behavior. pass makes a definition valid now, while the function or class still needs an implementation before it can perform a task.

The Python language reference calls pass a null operation and explains its use when syntax requires a statement but no code should run in its pass statement entry.

How to use pass in Python code blocks

Use pass on its own line at the indentation level where Python expects the block’s statement. These examples show a conditional branch, a function, and a class.

Step 1: Leave a conditional branch empty

This branch takes no action when the value is even. The other branch appends odd values to a new list.

def remove_evens(numbers):
    odds = []
    for number in numbers:
        if number % 2 == 0:
            pass
        else:
            odds.append(number)
    return odds

print(remove_evens([1, 2, 3, 4, 5, 6]))

Output

The loop continues after pass. The even number is ignored because the branch has no operation, not because pass changes the loop.

Step 2: Define a function without a body of work

A function definition still needs a statement in its body. Calling this function runs pass and returns None, Python’s default return value when a function reaches its end without returning a value.

def pending():
    pass

print(pending())

Output

pass makes the definition syntactically complete. It does not cause the function to return a useful result.

Step 3: Create an empty class

A class can also have a pass statement as its entire body when the class currently has no attributes or methods.

class Pending:
    pass

print(Pending.__name__)

Output

The class is defined with its name and can be used like other class objects. pass adds no methods or fields.

Common errors with the Python pass statement

pass is not a substitute for every kind of “do nothing.” Pick a statement that matches the behavior you want.

Situation Use Effect
Keep a required block empty pass Runs no operation, then execution continues normally
Skip the rest of this loop iteration continue Moves to the next iteration of the innermost loop
Explain unfinished work Comment or TODO Documents intent but does not make an empty block valid

For example, this function body is still empty because Python ignores comments when it parses a suite:

def pending():
    # TODO: implement this later

Running that exact definition with Python 3.11.16 produces this error because the comment is ignored and the function body has no statement.

IndentationError: expected an indented block after function definition on line 1

Add pass on its own indented line if the function must remain runnable before its implementation is ready. For loop control, see the Python tutorial’s section on break and continue.

Conclusion: Keep pass for code that must do nothing

Use pass when Python requires a statement but that block should do nothing. If the goal is to skip a loop iteration, continue expresses that behavior instead.

For related reading, see Python functions and Python indentation.

Frequently asked questions

These quick answers distinguish pass from the statements and placeholders it is often confused with.

What does pass do in Python?

pass is a null operation. It satisfies a code block that requires a statement while performing no operation.

Does pass skip a loop iteration?

No. pass does nothing and the loop proceeds to the next statement. Use continue to skip the rest of the current iteration.

Can a comment replace pass in an empty function?

No. Python ignores comments when parsing a code block, so a comment alone does not satisfy the required statement. Use pass for a valid empty function body.

Share.
Leave A Reply