Skip to content
Tutorials Center
My learning

Topics

Python Reference ยท Statements and Keywords

The pass statement

Reference for Python's pass statement: a do-nothing placeholder for empty blocks, stub functions and classes, silent except clauses, and pass versus the ellipsis.

pass is a statement that does nothing. Python needs at least one statement in every indented block, so when a block has no work to do yet (or deliberately never will), pass fills the space and keeps the syntax valid.

It is typically used for stubs: functions and classes you plan to write later, empty exception classes, and except branches that intentionally ignore an error.

Python
def todo():
    pass

Try it

Python Placeholders

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Python pass, ellipsis and ignoring errors

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Syntax

Python
pass

Return value: none. The statement has no effect and generates almost no code.

Usage notes

  • Where it helps: empty function and class bodies while you sketch a design, branches of if/elif that need no action, except clauses that ignore an error, and abstract or marker classes.
  • It is not continue. pass does nothing and the loop body carries on with the next statement; continue skips the rest of the iteration. It is also not break.
  • Not a comment. Unlike #, pass is executable (though free). It only exists to satisfy the grammar.
  • Alternatives: a docstring alone makes a valid body, so documented stubs rarely need pass. The ellipsis literal ... is common for stubs and in typing.Protocol or @overload definitions. For unimplemented functionality, raise NotImplementedError is safer than silently returning None.
  • Silent except: pass hides bugs. Catch the narrowest exception, and think about logging it. contextlib.suppress(...) states the intent clearly.
  • Needed after a colon only when nothing else follows. A block with any other statement does not need pass.
  • A common beginner confusion: pass inside a loop or if does not "do something later"; if you remove it, the code simply will not parse unless another statement takes its place.