How to use variable from previous scope in Python -
i have following code:
def test(): def printa(): def somethingelse(): pass print(a) aha = a[2] = [1, 2, 3] while true: printa() test()
i've noticed code work fine, if change aha
a
, says a
not defined.
is there way set a
value within printa?
in python 3, can set variable nonlocal
def test(): = [1, 2, 3] def printa(): nonlocal def somethingelse(): pass print(a) = a[2] while true: printa() test()
Comments
Post a Comment