I just started with python..
I got an error with for loop..
What is the problem ??
Traceback (most recent call last):
File "userentry.py", line 34, in <module>
userentry(p,i)
File "userentry.py", line 26, in userentry
for cl in len(mylist):
TypeError: 'int' object is not iterable
Please help me
You can just iterate over the list, you don’t iterate over the length of the list.
If you need to keep track of the index of the current item, use
enumerate:When you try to do
for cl in len(mylist), that’s like sayingfor cl in 5(if mylist has length of 5), which doesn’t really make sense. If you want to just iterate over the indices of a list, it’s best to use theenumerateexample above, but you can also doThough there are very few reasons to do this instead of just using the
enumerateversion above.