generator in Python

Generator functions allow you to declare a function that behaves like an iterator, i.e. it can be used in a for loop. This greatly simplifies your code and is much more memory efficient than a simple for loop.
```
def generate_numbers(n):
     num = 0
     while num < n:
         yield num
         num += 1
 total = sum(generate_numbers(1000))
 ```