Skip to content
CodeKruPro

When does the else of a try run?

QuizEasy-MediumPython onlyAsked in: Accenture, Capgemini, Cognizant, Infosys, TCS

The else block of a try statement is an optional part. What does this print?

try:
    x = 1
except Exception:
    print("no")
else:
    print("else", end=" ")
finally:
    print("finally")
  • else finally
  • finally
  • finally else
  • no finally

This question is part of Pro+

Pro+ opens every question in Interview Prep and the mock interview. Every article and the first 2 questions of each topic stay free. Hands-on Selenium and API tasks follow their course lesson's own lock.

See Pro+

Already have Pro+? Sign in