Python's iterators

Опубликовано: 15 Сентябрь 2017
на канале: Edik Mkoyan
811
2

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.


На этой странице сайта вы можете посмотреть видео онлайн Python's iterators длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь Edik Mkoyan 15 Сентябрь 2017, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 811 раз и оно понравилось 2 зрителям. Приятного просмотра!