eval.in

Paste #1028631

Python — CPython 3.4.1, pasted 9 months ago (json)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
def f(n):
    def b():
        nonlocal n
        n += 1
        return n
    return b

inc = f(0)
print(inc())
print(inc())

Program Output

1
2

OK (0.028 sec real, 0.031 sec wall, 8 MB, 28 syscalls)

Fork