Though I have coded in Python for pretty long time, the concept of scopes in Python is still a little unclear for me. Today, I studied a little bit the scopes in Python. To better illustrate what I've understood, I drew a sketch as shown below.
The 4 letters in LEGB stand for Local, Enclosing, Global, and Built-in. Python interpreter shall look up a variable content sequentially in following order: local -> enclosing -> global -> built-in.
Below are some snapshots of my tests:
refrence of this post:
Top comments (0)