Which exception does int("abc") raise?
Options
- TypeError
- ValueError (Correct option)
- KeyError
- SyntaxError
Answer
ValueError
Why
The type is correct (int() accepts strings), but this particular value cannot become a number → ValueError.
TypeError is when the TYPE itself is wrong, for example "2" + 2 (string plus int).
KeyError is a missing dictionary key; SyntaxError is code Python cannot even read.
Remember
Wrong value → ValueError. Wrong type → TypeError.