pass

An empty statement: a placeholder for code that does not do anything yet.

On this page

Example

#
Python
class ValidationError(Exception):
    pass

def calculate_bonus(points):
    pass

print(calculate_bonus(100))
print(issubclass(ValidationError, Exception))
Resultsaved result, you can check it
None
True

Definition and usage

#

The pass statement does nothing. It is needed wherever Python’s syntax requires a block of code, but you do not want to put anything in it yet, for example in an empty function, class, or branch of a condition.

It comes in handy when planning a program: you can first write the skeleton of your functions and classes with pass, and then gradually fill them in with code.

In empty exception classes (class MyError(Exception): pass), this is the standard notation. Instead of pass, you can also use the ellipsis ..., which works the same way in such places.

Syntax

#
Syntax
def function():
    pass

Good practices

#
  • Do not leave pass in finished code where there should be logic. It is easy to forget about it.
  • In empty except blocks, at least log the error instead of just using pass.

Related entries

#

Spotted a mistake or missing an example? Write to us.