Python's iterators

Publié le: 15 septembre 2017
sur la chaîne: 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.


Sur cette page du site, vous pouvez voir la vidéo en ligne Python's iterators durée heure minute seconde en bonne qualité , qui a été Téléchargé par l'utilisateur Edik Mkoyan 15 septembre 2017, Partagez le lien avec vos amis et connaissances, sur youtube cette vidéo a déjà été regardée 811 fois et il a aimé 2 téléspectateurs. Bon visionnage!