0
What is the iterable?
5 Answers
+ 1
Something you can loop through.
+ 1
A list for example
0
like what
0
what is the meaning of iterable
and how can list be an iterable??
0
An iterable is any object, not necessarily a data structure, that can return an iterator (with the purpose of returning all of its elements).
An iteration is a object that has the function __next__() which gives back the next element. If you use a for loop to go through a list like for example
for x in list:
do_stuff_here()
It gets the iterator from list and uses __next__() every loop iteration to put the next element in x and stops looping if __next__() returns no object
You can use iterators to use the for ... in ... Syntax in your Own classes. See this for more information: http://nvie.com/posts/iterators-vs-generators/