Generators are functions that return an iterable generator object. Because the values from the generator object are fetched one at a time rather than the entire list at once, you can use a for-loop, next(), or list() function to get the actual values. Generator functions act just like regular functions with just one difference that they use the Python yield keyword instead of return .
Code:
def test_sequence():
num = 0
while num<10:
yield num
num += 1
for i in test_sequence():
print(i, end=",")
Output: 0,1,2,3,4,5,6,7,8,9