Friday , September 20 2024

What is the expected result of the following snippet? try: raise Exception except: print(“c”) except BaseException: print(“a”) except Exception: print(“b”)

Questions BankCategory: Python Essentials 2What is the expected result of the following snippet? try: raise Exception except: print(“c”) except BaseException: print(“a”) except Exception: print(“b”)
What is the expected result of the following snippet?

try:
    raise Exception
except:
    print("c")
except BaseException:
    print("a")
except Exception:
    print("b")
  • a
  • The code will cause a syntax error
  • 1
  • b

Explanation: Executing the code will result in a SyntaxError exception, because the default except branch must be the last except branch (in this example, it’s the first).

More Questions: Python Essentials 2 (PE2) Course Final Test