-1
def fun():
    s=0
    for i in range(10):
        s+=1
    return s

print(fun())

def fun():
    s = 0
    for i in range(10):
        s += i
        yield s

print(fun())

for i in fun():
    print(i)

Output:

10
<generator object fun at 0x000001DF83289CB0\>
0
1
3
6
10
15
21
28
36
45

Question:
I have understood

10
<generator object fun at 0x000001DF83289CB0\>

this part of the output. But unable to understand

0
1
3
6
10
15
21
28
36
45

this part.

Please help me with this.

JonSG
  • 10,542
  • 2
  • 25
  • 36

0 Answers0