def makeInc (x, step):
def next():
nonlocal x, step
x = x + step
return x
return next
x = makeInc (0, 1)
y = makeInc (0, 10)
x1=x()
x2=x()
y1=y()
y2=y()
print( x1, x2, y1, y2)
The output is 1 2 10 20. I am not sure why it gives these outputs, can anyone explain it in detail? Thanks!