Iterators and Generators in Python:

 Iterators and Generators in Python:


Python iterate is an object which contains some countable values and it can be traversed over again through the values. Some of the examples for iterable objects in python are list, sets, tuples, strings etc

Example for Python iterators


Generators in python create iterations in a simple way. It is very easy to create generators. It is a normal function with yield instead of return. Yield returns the same value of return.

The difference between yield and return is the return exits the function but yield pauses the function and continues the call. Generator function may contain one or more yield statements.


Python Generators

Post a Comment