Python Forum

Full Version: 'int' object is not iterable
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello Everyone!

Why do I see the error ('int' object is not iterable) when I add the method list?
list02=[a,b,c,d,e,f,g,h,i,j]
for item,item1 in enumerate(list02):
    print(list(item))
And thank you.
list() converts to a list, but an int only has one item and can't be a list.
enumerate returns an index and a value;
thus your code, item is an integer (index within list) and item 1 is the value at that index.
in addition, your print is incorrect, print(item) will print the index, whereas
print(item1) will print the value of the element at index item