Skip to content

Instantly share code, notes, and snippets.

@IndhumathyChelliah
Last active Jul 23, 2020
Embed
What would you like to do?
def gen(n):
for i in range(n):
yield i
g=gen(3)
print (type(g))#Output:<class 'generator'>
#Generator function returns an iterator.
# We can access the element by using next() function or using for loop.
print (next(g))#Output:0
print (next(g))#Output:1
print (next(g))#Output:2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment