Iterators are objects that can be iterated upon. In this tutorial, you will learn how iterator works and how you can build your own iterator using _iter_ and _next_ methods.
Python Iterators
Iterators are everywhere in Python. They are elegantly implemented within for loops, comprehensions, generators etc. but hidden in plain sight.
Iterator in Python is simply an object that can be iterated upon. An object which will return data, one element at a time.
Technically speaking, Python iterator object must implement two special methods, __iter__() and __next__(), collectively called the iterator protocol.
An object is called iterable if we can get an iterator from it. Most of built-in containers in Python like: list, tuple, string etc. are iterables.
The iter() function (which in turn calls the __iter__() method) returns an iterator from them.
On this page of the site you can watch the video online Python's iterators with a duration of hours minute second in good quality, which was uploaded by the user Edik Mkoyan 15 September 2017, share the link with friends and acquaintances, this video has already been watched 811 times on youtube and it was liked by 2 viewers. Enjoy your viewing!