Sunday, 30 November 2025

Python try catch

 def test():

    try:

        return 1  # This executes first

    finally:

        return 2  # This executes last and OVERRIDES the previous return


result = test()

print(result)  # Output: 2

No comments:

Post a Comment