The pass is a statement in python which is used as a placeholder for implementations inside functions, loops, etc.

Python pass statement allows to bypass the syntactical requirement i.e the code blocks such as def, if, class, etc cannot be empty.



Suppose you are designing a class with some methods you don’t want to implement yet. what will you do? Since you cannot leave the method empty.

In this case, pass is used not to produce an error:

class Dog:
  def eat():
  def walk():
    print("Dog can walk")

Similarly, we can use a pass statement inside an empty loop that doesn’t have any implementation yet.

def doSomething():
  for x in range(10):

What is the difference between comment and pass?

In Python, pass is similar to a null statement. Comments in python are ignored by the compiler but pass gets executed by the compiler. This is the major difference between comment and pass in the Python programming language.

Leave a Reply