Why does untriggered assignment changed `nonlocal` behavior? [duplicate]
问题 This question already has answers here : In Python, variables inside if conditions hide the global scope even if they are not executed? (4 answers) Closed last year . Today I'm reading python change log and meet the nonlocal keyword and did some experiment with it. I find a confusing situation where untriggered assignment will change the nonlocal keyword behavior, please see the example below. def a(): x = 'a' def b(): def c(): nonlocal x x = 'c' c() b() print(x) a() >>> python3 test.py c def