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.
Nesta página do site você pode assistir ao vídeo on-line Iterator, Iterables and Generator - Python Tutorial in Tamil duração hora minuto segundo em boa qualidade , que foi baixado pelo usuário Surendar Manoj 29 Janeiro 2022, compartilhe o link com seus amigos e conhecidos, no youtube este vídeo já foi visto 2,999 vezes e gostou 70 espectadores. Boa visualização!