Codectionary / Developer documentation / Python

pass

pass is a statement that performs no operation. It supplies a statement where Python requires a nonempty body, for example a placeholder function or a minimal exception class. Execution continues normally after it.

How it works

An empty block or a block containing only a comment is a syntax error. pass makes that block syntactically valid without adding behaviour. A function containing only pass returns None when called.

pass does not skip the rest of a loop iteration, end a function or raise an error. Those jobs belong to continue, return and raise respectively.

Some empty bodies are intentional and complete: a custom exception can inherit all its behaviour from Exception and use pass solely to define a distinct type. A placeholder function, however, still needs implementation.

Common mistakes and boundaries

Do not silently use pass in a broad except block. It hides failures and may leave the program in an invalid state.

When an unimplemented operation must not appear to succeed, explicitly raise NotImplementedError with a useful message instead of returning None accidentally.

Try it yourself

Put print("after") immediately after pass inside a loop. Confirm that it still runs. Compare this with continue, then explain why the empty exception class is useful even though it adds no methods.

Syntax

pass

Examples

Placeholder Function

Stubbing out a function you plan to implement later.

def send_email(to, subject, body):
    pass  # TODO: implement email sending logic

def calculate_discount(price):
    pass  # not yet implemented

send_email("user@example.com", "Hi", "Hello there")  # runs, does nothing yet
  1. Both functions are placeholders. Calling send_email sends nothing and returns None; its name alone does not mean the operation happened.
  2. This example intentionally produces no output.

Empty Class

Defining a class body with no attributes or methods yet.

class CustomError(Exception):
    pass

try:
    raise CustomError("Something went wrong")
except CustomError as error:
    print(error)
  1. The class inherits exception behaviour. The example raises and catches its specific type so the demonstration completes without an uncaught traceback.
  2. Expected output: Something went wrong

Placeholder in Conditional Branches

Intentionally leaving one branch of an if statement empty while working on the others.

status = "pending"

if status == "approved":
    print("Processing order")
elif status == "pending":
    pass  # intentionally no action yet
elif status == "rejected":
    print("Order cancelled")
  1. The pending branch intentionally performs no work. No output appears, and execution can continue after the conditional.
  2. This example intentionally produces no output.

Best practices

  • Use pass as a temporary placeholder while sketching out code structure, then replace it with real logic
  • Prefer pass over leaving a block genuinely empty, since Python's syntax doesn't allow empty blocks at all
  • Use pass for minimal custom exception classes that only need a distinct type, not new behavior
  • Don't forget to come back and implement code left as pass - consider adding a comment or TODO alongside it

Runtime & versions

Python interpreter. Feature availability depends on the language and runtime version used by your project; consult the official reference below.

Python language reference

Specifications & further reading