'int' object is not iterable
时间: 2023-10-19 21:19:17 浏览: 132
《Python数据分析基础》笔记:“TypeError, ‘int’ object is not iterable”
5星 · 资源好评率100%
This error occurs when you try to iterate over an integer object, which is not possible since integers are not iterable.
For example, if you have a variable 'x' that is an integer and you try to loop through it like this:
```
x = 5
for num in x:
print(num)
```
You will get the error message 'int' object is not iterable.
To fix this error, you need to make sure that you are only iterating over iterable objects such as lists, tuples, and strings. If you need to iterate over integers, you can do so by converting them to iterable objects using the range() function or by wrapping them in a list or tuple.
阅读全文