Can we remove finally: ? | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 1

Can we remove finally: ?

What is the difference between these codes : Code 1: try: x except: y finally: z Code 2: try: x except: y z

20th Jun 2020, 5:06 PM
Mr.Lightning
Mr.Lightning - avatar
2 ответов
+ 4
You can remove finally if your application does not need to perform any operation if exception raised while handling exception as shown below. try: raise ValueError("code1") except ValueError as e: print("code 1 except") raise ValueError("code11") finally: print('code 1 finally' ) Code under finally block will be executed even if the exception raised while handling exception. Run above code and check with and without finally block.
20th Jun 2020, 6:13 PM
$¢𝐎₹𝔭!𝐨𝓝
$¢𝐎₹𝔭!𝐨𝓝 - avatar
+ 1
𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 no I meant the difference of them in output
20th Jun 2020, 5:26 PM
Mr.Lightning
Mr.Lightning - avatar