Why is this required if we have loops

why is this required if we have loops

hi @Anuvrat99
An iterable is an object capable of returning its members one by one . Said in other words, an iterable is anything that you can loop over with a for loop in Python.

You can use an iterator to manually loop over the iterable it came from. A repeated passing of iterator to the built-in function next() returns successive items in the stream . Once, when you consumed an item from an iterator, it’s gone. When no more data are available a StopIteration exception is raised. Under the hood, Python’s for loop is using iterators.
Iterator is actually generator which has the ability to be iterated through only once, and for for loop we can iterate for as many times we want.

Hope this might help :slightly_smiling_face:

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.