Common causes
- Using + to combine a string with an integer: 'Count: ' + 5
- A variable holds a number but you assumed it was a string
- Building a message string by concatenating a string with a function's return value that returns a number
- Mixing data types when building SQL queries or log messages with +
How to fix it
- Convert the non-string value to a string: 'Count: ' + str(5)
- Use an f-string instead — cleaner and avoids the issue: f'Count: {count}'
- Use .format(): 'Count: {}'.format(count)
- Use a comma in print() to avoid concatenation entirely: print('Count:', count)
Example
Traceback (most recent call last):
File "app.py", line 2, in <module>
print('Score: ' + score)
TypeError: can only concatenate str (not "int") to strConcatenating a string literal with an integer variable using +
Have a different error?
Paste any error message into the Error Translator to get an instant explanation.
