N
Nick
Hello,
It must be simple but it seems I misunderstand scopes in Python...
Could someone out there please explain to me why this is printed?
2 {0: 1, 1: 1}
instead of
2 {}
Thanks.
N.
---- test.py ----
g = 0
di = {}
def test():
global g
di[g] = 1
g += 1
test()
test()
print g, di
It must be simple but it seems I misunderstand scopes in Python...
Could someone out there please explain to me why this is printed?
2 {0: 1, 1: 1}
instead of
2 {}
Thanks.
N.
---- test.py ----
g = 0
di = {}
def test():
global g
di[g] = 1
g += 1
test()
test()
print g, di