Exceptions(finally)"python 3" | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Exceptions(finally)"python 3"

Is there any kind of difference between : try: print(1/0) except: print("Error") finally: print("finished") and : try: print(1/0) except: print("Error") print("finished")

9th Jun 2017, 1:16 PM
Mahmoud Gazy
Mahmoud Gazy - avatar
1 Answer
0
Yes. "finished"is always printed in the first code. In the second one, it's only printed if the execution reaches it. E.g., if you add "return" immediately after "try", the former will still print "finished", but the latter won't.
9th Jun 2017, 5:50 PM
Igor B
Igor B - avatar