Question
It seems like “global” and “nonlocal” would be the same thing. How are these keywords different in Python?
Answer
Variables inside a function are local by default; variables outside of functions are global by default. (This was taken from https://www.programiz.com/python-programming/global-keyword.) This answer/article addresses the “LEGB lexical scoping rule” (taken from page 872 of Learning Python).
…
Continue reading “What is the Difference between global and nonlocal in Python?”