Friday , September 20 2024

What will be the result of executing the following code? try: raise Exception(1,2,3) except Exception as e: print(len(e.args))

Questions BankCategory: Python Essentials 2What will be the result of executing the following code? try: raise Exception(1,2,3) except Exception as e: print(len(e.args))
What will be the result of executing the following code?

try:
    raise Exception(1,2,3)
except Exception as e:
    print(len(e.args))
  • it will print 2
  • it will print 1
  • it will print 3
  • it will raise an unhandled exception

Explanation: The except branch is executed and intercepts the object carrying information about the exception. The args property, which is a tuple, gathers all arguments passed to the Exception class constructor: 1, 2, and 3. The len function computes the length of the tuple (i.e. 3), which is printed to the console.

More Questions: Python Essentials 2 – Module 3 Test