-
-
Save IndhumathyChelliah/94f52a4d63fabfc3d3969fae046feb92 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
g=(n for n in range(1,11)) | |
#Returns an generator object which is an iterator [contains element from 1 to 10] | |
print (g) #Output: <generator object <genexpr> at 0x0116C728> | |
#We can iterate through the iterator object using for loop or using next() function. | |
print (next(g))#Output:1 | |
print (next(g))#Output:2 | |
print (next(g))#Output:3 | |
#for loop will iterate through the remaining elements (starting from fourth element) | |
for i in g: | |
print (i, end=" ") #Output: 4 5 6 7 8 9 10 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment