Is there any functional difference in Python between a “try” statement and an “if” statement?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I believe you’re asking about the paradigm “Easier to ask for forgiveness than for permission” which is sometimes quoted as a Python guideline.
In this context
try / exceptcorresponds to trying and asking for forgiveness, whileifcorresponds to asking for permission then trying.Have a look: http://docs.python.org/glossary.html#term-eafp