Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (47.6k points)

I am in the process of learning Python and I have reached the section about the pass statement. The guide I'm using defines it as being a Null statement that is commonly used as a placeholder.

I still don't fully understand what that means though. Can someone show me a simple/basic situation where the pass statement would be used and why it is needed?

1 Answer

0 votes
by (106k points)
edited by

To know what is a  pass statement and how it works, let's suppose you are creating a class with some methods those you do not want to implement at the time of creating the class.

class Abc(object):

def method_A(self):

pass 

def method_B(self):

      print ("I am in method_B function")

So in the above code, I have not used method_A() function so I have written pass statement in the function block so that it will be skipped to the next line of code without affecting the code. If I have not used pass statement it would have thrown an error.

IndentationError: expected an indented block

In one word if you want to define the pass statement then you can say that it is a placeholder.

To know more about this you can have a look at the following video tutorial:-

Related questions

0 votes
1 answer
asked Dec 11, 2020 in Python by laddulakshana (16.4k points)
0 votes
1 answer
asked Oct 11, 2019 in Python by Tech4ever (20.3k points)
0 votes
1 answer
asked Sep 20, 2019 in Python by Sammy (47.6k points)
0 votes
1 answer
asked Sep 17, 2019 in Python by Sammy (47.6k points)
0 votes
1 answer

Browse Categories

...