Python Pass Statement

In python, the pass statement is just a null statement, and it useful when you perform nothing even after execution.

 

If you want to create a function or loop with an empty body for the future purpose, the compiler will not allow it, but by using a pass statement you can create a function or loop without any implementation.

Python Pass Statement Example

Following is the example of using a pass statement in python for loop to do nothing even after execution.

 

for x in range(5):

  if x == 3:

    pass

  print(x)

print("Loop Execution Finished")

When you execute the above python program, you will get the result like as shown below.

 

0

1

2

3

4

Loop Execution Finished

If you observe the above result, even after executing the pass statement inside of for loop, it continued the statements' execution.

 

Same as for loop, you can use pass statements to define empty functions, classes, etc. based on your requirements.