Does Python scoping rule fits the definition of lexical scoping?
问题 According to my programming language class, in a language that uses lexical scoping The body of a function is evaluated in the environment where the function is defined, not the environment where the function is called. For example, SML follows this behavior: val x = 1 fun myfun () = x val x = 10 val res = myfun() (* res is 1 since x = 1 when myfun is defined *) On the other hand, Python does not follow this behavior: x = 1 def myfun(): return x x = 10 myfun() # 10 since x = 10 when myfun is