python
type_error
ai_generated
true
TypeError: unsupported operand type(s) for +: 'int' and 'str'
ID: python/typeerror-unsupported-operand
95%Fix Rate
95%Confidence
50Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 311 | active | — | — | — |
Root Cause
Binary operation between incompatible types. Common: concatenating str + int without conversion.
genericWorkarounds
-
95% success Explicitly convert types: str(num) for concat, int(s) for math
result = 'Count: ' + str(count) # or f'Count: {count}'Sources: https://docs.python.org/3/library/stdtypes.html#str
-
95% success Use f-strings for mixed type formatting: f'{name}: {value}'
f'{name}: {value}'Sources: https://docs.python.org/3/reference/lexical_analysis.html#f-strings
Dead Ends
Common approaches that don't work:
-
Convert everything to str
60% fail
May hide a logic error — you might want numeric addition, not concatenation
-
Use eval() to auto-detect types
90% fail
eval is a security risk and doesn't fix type issues
Error Chain
Frequently confused with: