python
type_error
ai_generated
true
TypeError: 'int' object is not iterable
ID: python/typeerror-not-iterable
95%Fix Rate
95%Confidence
50Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 311 | active | — | — | — |
Root Cause
Trying to iterate over a non-iterable. Common: for x in some_int, or sum(x) where x is not a list.
genericWorkarounds
-
95% success Check the variable type — it's probably returning a single value instead of a collection
Check the variable type — it's probably returning a single value instead of a collection
Sources: https://docs.python.org/3/library/functions.html#isinstance
-
88% success If you need to iterate over digits/chars, convert first: str(num) or [num]
str(num) or [num]
Sources: https://docs.python.org/3/library/stdtypes.html#str
Dead Ends
Common approaches that don't work:
-
Wrap in list() blindly
70% fail
Doesn't fix the root cause — the variable shouldn't be an int
-
Add __iter__ to the class
65% fail
Usually the variable is wrong type, not missing __iter__
Error Chain
Frequently confused with: