Skip to main contentSkip to solution

Identify the type of error shown in the code:

print(10 + '5')

Solution

✅ Correct Option: 1

Python cannot add an integer and a string with the ++ operator. Here 1010 is an int and '5' is a str, so the operation is applied to incompatible types. Python raises TypeError: unsupported operand type(s) for +: 'int' and 'str'.


ValueError: raised when the type is correct but the value is not suitable, for example int('abc'). Here the problem is the type itself, not the value.

NameError: raised when a variable or function name is not defined. Nothing undefined is used here.

IndexError: raised when a sequence index is out of range. No indexing happens here.

To fix it, convert one operand: 10 + int('5') gives 15, or str(10) + '5' gives '105'.

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question