Skip to content

Instantly share code, notes, and snippets.

@IndhumathyChelliah
Last active July 23, 2020 03:12
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/94f52a4d63fabfc3d3969fae046feb92 to your computer and use it in GitHub Desktop.
Save IndhumathyChelliah/94f52a4d63fabfc3d3969fae046feb92 to your computer and use it in GitHub Desktop.
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