TypeError: 'int' object is not iterable
时间: 2023-10-16 15:11:02 浏览: 46
This error message typically occurs when you try to iterate over an integer object. For example, if you try to loop over an integer using a for loop, you will get this error message.
Here is an example of how this error can occur:
```
number = 5
for digit in number:
print(digit)
```
In this example, we are trying to loop over the integer `number` using a for loop. However, since an integer is not an iterable object, we get the error message "TypeError: 'int' object is not iterable".
To fix this error, you need to make sure that you are iterating over an iterable object. For example, if you want to loop over the digits of an integer, you can convert the integer to a string and then loop over the characters in the string:
```
number = 12345
for digit in str(number):
print(digit)
```
In this example, we first convert the integer `number` to a string using the `str()` function. We can then use a for loop to iterate over the characters in the string, which gives us each digit of the original integer.