+ 2
How does pass work in python?
For what purpose we use?
7 Antworten
0
Lucifer ,
Suppose you come in a situation where you have to handle an exception using try and except statement in python or to check a particular condition using if-statement in python.
There may a situation come in which when you arrive or come in a particular situation or condition or while handling a particular exception, you don't want anything to happen.
For example, you may come in a situation where you don't want to execute any kind of code when the age of user is below 5 years or when you encountered an IndexError exception, you don't want to do anything and just skip it. At that time, you can use a keyword, similar to break or continue, called as 'pass' which basically means to do nothing.
That's it:)
+ 6
Lucifer
The pass statement in Python is used when a statement is required syntactically but you do not want any command or code to execute. The pass statement is a null operation; nothing happens when it executes.
source:
https://stackoverflow.com/questions/13886168/how-to-use-the-pass-statement
I hope I was helpful
+ 4
Jitendra Singh, what is LPS????
+ 1
Hey Ayush, Are u the same student from LPS?
+ 1
Nothing, I just thought something else for a while, sorry for disturbing you
0
basically you add a pass statement when you don't want any code or command to run
i.e
def greet():
pass
greet('this will run without giving you any error')
0
try:
except:
pass
no matter how wrong a code is inside try, it will always be ignored.