+ 2

How does pass work in python?

For what purpose we use?

10th May 2019, 7:33 PM
Waseem Khan
Waseem Khan - avatar
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:)
11th May 2019, 4:43 AM
Ayush Sinha
Ayush Sinha - avatar
+ 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
10th May 2019, 7:36 PM
Alessio Benvenuti
Alessio Benvenuti - avatar
+ 4
Jitendra Singh, what is LPS????
11th May 2019, 9:05 AM
Ayush Sinha
Ayush Sinha - avatar
+ 1
Hey Ayush, Are u the same student from LPS?
11th May 2019, 5:00 AM
Jitendra Singh
Jitendra Singh - avatar
+ 1
Nothing, I just thought something else for a while, sorry for disturbing you
11th May 2019, 12:13 PM
Jitendra Singh
Jitendra Singh - avatar
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')
10th May 2019, 9:59 PM
Adigun Olamide
Adigun Olamide - avatar
0
try: except: pass no matter how wrong a code is inside try, it will always be ignored.
12th May 2019, 4:45 AM
Choe
Choe - avatar