Python Tutorial - Pass Statement

  1. Python pass Statement
  2. pass Statement Example

In this section, you will learn Python pass statement.

Python pass Statement

pass is actually a null statement which is generally used as a placeholder. When you want to declare a function or a loop but not want to provide the implementation then you can use pass statement. It is similar to ; in C programming language or nop in assembly language.

The pass statement will result in no operation (NOP) which means nothing happens when pass is executed.

So what is the difference between pass and Python comments when nothing happens to both of them?

The comments are ignored and not executed, but pass statement will be executed resulting in nothing.

The following is the syntax of pass in Python:


If you want to provide the implementation of a loop or function in the future then you have to use the pass statement because a function or a loop can never have an empty body in Python.

pass statement creates an empty body for you.

pass Statement Example

l = ['p', 'y', 't', 'h', 'o', 'n']
for i in l:

So here, for loop has an empty body indicated by pass statement. If there is no pass statement and body of for is left empty you will have a SyntaxError - expected an indented block.

Similarly, pass can also be used in classes and functions when you plan to implement classes and function in the future. Consider the example below:

def function(args):
class ABC:
Write for us
DelftStack articles are written by software geeks like you. If you also would like to contribute to DelftStack by writing paid articles, you can check the write for us page.