One of the reasons for Python's popularity is its simplicity and ease of use. The Pass statement, along with other control structures, helps make Python even more user-friendly. In this tutorial, we will explore the purpose of the Pass statement, its syntax, and different scenarios where it can be used. By the end of this tutorial, you will have a clear understanding of the Pass statement and how to use it effectively in your Python code. So, let's get started!

Pass statement in Python

  • Pass statement in python is a statement that does nothing.
  • It is usually used as placeholder for the code that we'll write in future.
  • For example, suppose we have an if..else statement but we are currently not sure about the logic that we need to insert in the else part.
  • If we leave the else part blank that the interpreter will raise an error, hence we need to write at-least one valid python statement.
  • This is where pass statement comes in handy.
  • pass is a valid python statement yet it does nothing.
  • Thus we can write the pass statement to avoid error, and yet skip the main logic for the future.
  • pass statement can be used with many python constructs like :
  • Code Sample :

for index in range(2):
    print("This is the outer loop")
    print(f"Value of index = {index}")

    for cnt in range(3):

print("Coming out of for loop")
print(f"Value of index = {index}")

# Output
# This is the outer loop
# Value of index = 0

# This is the outer loop
# Value of index = 1

# Coming out of for loop
# Value of index = 1

Prev. Tutorial : Continue statement

Next Tutorial : Enumerate function