In [6]:
def firstn(n):
    num = 0
    while num < n:
        yield num
        num += 1
thesum = sum(firstn(100000))
thesum


Out[6]:
4999950000

In [ ]: