Skip to content

Instantly share code, notes, and snippets.

Last active Jul 23, 2020
What would you like to do?
def gen(n):
for i in range(n):
yield i
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