what is the difference between iterable and iterator?
For list x=[1,2,3,4] it is iterable, what is the iterator here?
What is the difference between iterable and iterator?
Hey @nikhil_0406, Iterable is an object, which one can iterate over. It generates an Iterator when passed to iter()
method. Iterator is an object, which is used to iterate over an iterable object using next() method. Iterators have __next__()
method, which returns the next item of the object. If u want to see some examples with detail, please go through the following links :
I hope this helps !
Happy Learning !
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.