Python Loop Generator using python stopiteration || Generators || Python

In this we are going to see how to get Python Loop Generator using python stopiteration, using Generators in Python Programming Language.


def square_of_sequence(x):
    for i in range(x):
        yield i*i

gen = square_of_sequence(5)
while True:
    try:
        print("Received on next(): ", next(gen))
    except StopIteration:
        break

# Coded By Dhiraj Shelke

#ENJOY CODING


Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post