It differs from regular functions in that it uses the
yield keyword instead of return. Each call to next(generator) produces the next value from the sequence.Example:
def multiple_generator(x, n):
for i in range(1, n + 1):
yield x * i
multiples_of_5 = multiple_generator(5, 3)
print(next(multiples_of_5)) # 5
print(next(multiples_of_5)) # 10
print(next(multiples_of_5)) # 15
https://t.me/DataScience4 ❤️
