What is the output of the following? try: x = 1 / 0 except ZeroDivisionError: x = -1 finally: print(x)

Python Medium
Select the correct answer: Single Choice

Key points

  • The code handles a ZeroDivisionError using a try-except block
  • The value of x is set to -1 in the except block
  • The finally block always executes, printing the final value of x

Ready to go further?