try except python | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

try except python

why is this code returning 3. Can someone explain this code to me? https://code.sololearn.com/cx4UUiDD5TCf

2nd Feb 2022, 11:35 AM
Gajendra Sonare
Gajendra Sonare - avatar
1 Answer
+ 1
1/0 raise divideByzero exception , in Catching also 1/0 , again raise error but it has no exception catching, comes out but after finally gets executed so finally returns 3 Finally block always executed whether exception raise or not.. so that's why it prints 3, even without exception also... try 1/2 instead of 1/0 , answer will be same.
2nd Feb 2022, 11:53 AM
Jayakrishna 🇮🇳