Skip to content

Instantly share code, notes, and snippets.

@IndhumathyChelliah
Last active July 23, 2020 03:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IndhumathyChelliah/900289f58ae3a67f209638b5f1faa710 to your computer and use it in GitHub Desktop.
Save IndhumathyChelliah/900289f58ae3a67f209638b5f1faa710 to your computer and use it in GitHub Desktop.
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