'int' object is not iterable
时间: 2023-10-19 16:06:27 浏览: 89
This error occurs when you try to iterate over an integer object using a loop or a function that expects an iterable object.
For example, if you try to iterate over an integer using a for loop like this:
```
num = 5
for i in num:
print(i)
```
You will get the 'int' object is not iterable error because the integer object 'num' cannot be iterated over.
To fix this error, make sure that you are using an iterable object such as a list, tuple, or string in your loop or function. If you need to convert an integer to an iterable, you can do so by converting it to a string and then using the string as an iterable:
```
num = 5
for i in str(num):
print(i)
```
This will print out each digit of the integer 'num' on a separate line.
阅读全文