Identify the type of error shown in the code:
print(10 + '5')
Identify the type of error shown in the code:
print(10 + '5')
Solution
Python cannot add an integer and a string with the operator. Here 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'.
Related questions:
2025: 16 May Shift 1
2025: 27 May Shift 2
2025: 15 May Shift 2
2026: 26 May Shift 1
2026: 18 May Shift 2