def counter(): i = 0 while True: yield i i += 1 This is a generator function that returns an infinite sequence of integers, starting from 0. What is infinite series An infinite series is a sequence of numbers that continues to grow without end. In Python, an infinite series can be ...
Yield: This is like hitting the pause button. The processor waits until something new happens (like getting a message from the user). The processor is on standby mode while yielding. It waits if there is any new external event, like a new message from the user, and then it will be act...