Facebook Page Twitter Page LinkedIn Page
× Python Tutorial Python Advanced Python Resources Python Libraries


The Python pass keyword is used as a placeholder for future code. Python does not allow to create conditional statements, loops, functions or classes with empty codes and raises exception if created with empty codes. Instead of empty codes, pass keyword can be used to avoid such errors.

Example:

In the below example, empty if statement is created, which raises exception upon execution.

MyString = "Python"
if MyString is "Python":

print("pass statement allows to create objects with empty codes.")

The output of the above code will be:

IndentationError: expected an indented block

Example:

When pass statement is used instead of empty if statement, no exception will be raised and program will execute next line of codes.

MyString = "Python"
if MyString is "Python":
  pass

print("pass statement allows to create objects with empty codes.")

The output of the above code will be:

pass statement allows to create objects with empty codes.

Example:

Similarly, the pass statement can be used to create empty loops, functions or classes.

for i in range(1, 10):
  pass

def MyFunction():
  pass

class MyClass:
  pass

print("pass statement allows to create objects with empty codes.")

The output of the above code will be:

pass statement allows to create objects with empty codes.

❮ Python Keywords