What is the output of the following? try: x = 1 / 0 except ZeroDivisionError: x = -1 finally: print(x)
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?
