Repaso
Español
PythonCorePY-59

Which exception does int("abc") raise?

Options

  1. TypeError
  2. ValueError (Correct option)
  3. KeyError
  4. 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.

Key terms

Practice this question in Repaso