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

Python pass statement allow 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 to not to produce any error.

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

Similarly, it can be used inside an empty loop for which you have not decided any implementation yet.

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

What is the difference between comment and pass?

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

Comment below your doubts or suggestion.

Leave a Reply