Python Programming - Exception Handling - Discussion

Discussion Forum : Exception Handling - General Questions (Q.No. 7)
7.
Consider the following Python code:
try:
    num = int("abc")
except ValueError:
    print("Invalid conversion")
else:
    print("Conversion successful")
What will be the output of this code?
Invalid conversion
Conversion successful
ValueError: invalid literal for int() with base 10: 'abc'
No output, it will raise an exception
Answer: Option
Explanation:
The try block attempts to convert the string "abc" to an integer, resulting in a ValueError. The except block is executed, printing "Invalid conversion."
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.