-
-
Save IndhumathyChelliah/900289f58ae3a67f209638b5f1faa710 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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