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.
Auf dieser Seite können Sie das Online-Video Iterator, Iterables and Generator - Python Tutorial in Tamil mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Surendar Manoj 29 January 2022 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 2,999 Mal angesehen und es wurde von 70 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!