Python Programming - Exception Handling - Discussion

Discussion Forum : Exception Handling - General Questions (Q.No. 33)
33.
Consider the following Python code:
try:
    x = int("abc")
except ValueError as e:
    x = "Error: " + str(e)
What will be the value of "x" after the execution of this code?
"Error: invalid literal for int() with base 10: 'abc'"
"abc"
0
None
Answer: Option
Explanation:
The try block attempts to convert the string "abc" to an integer, causing a ValueError. The except block captures the exception and assigns an error message to "x."
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.