All Python errors
TypeError in Python: wrong type of value
TypeError means an operation or a function received a value of a type it cannot work with. To fix it, check the types on that line and convert them explicitly, for example str(5) to join a number with text.
Code with the error
apples = 5
print("Apples: " + apples)
Error message (Python 3.12, last line)
Corrected code
apples = 5
print("Apples: " + str(apples))
Output
Apples: 5
Common causes
- Text and a number are joined with +.
- A function gets too many or too few arguments.
- Brackets after something that is not a function, such as a number.
- Indexing a value that has no items, for example None or a number.
Practise in the course
Lesson: StringsFrequently asked questions
How do I find out the type of a value?
Print type(value): Python shows int, str, list or another type.
Is there a way to join text and numbers without str()?
Yes, an f-string does it: f"Apples: {apples}".