0 votes
1 view
in Python by (47.8k 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 (107k 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 Oct 11, 2019 in Python by Tech4ever (20.3k points)
0 votes
1 answer
asked Sep 20, 2019 in Python by Sammy (47.8k points)
0 votes
1 answer
asked Sep 17, 2019 in Python by Sammy (47.8k points)
0 votes
1 answer
0 votes
1 answer
asked Sep 24, 2019 in Python by Sammy (47.8k points)
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...