Iterator, Iterables and Generator - Python Tutorial in Tamil

Publicado el: 29 January 2022
en el canal de: Surendar Manoj
2,999
70

An iterator is an object that contains a countable number of values.
Technically, in Python, an iterator is an object which implements the iterator protocol, which consists of the methods __iter__() and __next__().

Lists, tuples, dictionaries, and sets are all iterable objects. They are iterable containers which you can get an iterator from. All these objects have an iter() method which is used to get an iterator.

A python generator function lends us a sequence of values to python iterate on.

We used a function to create generator. But in creating an iterator in python, we used the iter() and next() functions.

A generator in python makes use of the ‘yield’ keyword. A python iterator doesn’t.

Python generator saves the states of the local variables every time ‘yield’ pauses the loop in python.

An iterator does not make use of local variables, all it needs is iterable to iterate on.

A generator may have any number of ‘yield’ statements.

You can implement your own iterator using a python class; a generator does not need a class in python.

To write a python generator, you can either use a Python Function or a comprehension. But for an iterator, you must use the iter() and next() functions.

Generator is efficient for writing fast and compact code. This is an advantage over Python iterators. They are also simpler to code than do custom iterator.

Python iterator is more memory-efficient.


En esta página del sitio puede ver el video en línea Iterator, Iterables and Generator - Python Tutorial in Tamil de Duración hora minuto segunda en buena calidad , que subió el usuario Surendar Manoj 29 January 2022, comparta el enlace con amigos y conocidos, en youtube este video ya ha sido visto 2,999 veces y le gustó 70 a los espectadores. Disfruta viendo!