In many resources I found "scope" and "namespaces" are used interchangeably, which seems a bit confusing since they mean different things.
- Scope defines the region of the code where a name is available.
- The LEGB rule defines the way names are looked up.
- Namespace is a place where you look up names.
Then I read:
- "names are bind to a namespace according to where they are assigned..." (which I believe is the deal with scopes in lexical scoping).
- "functions add an extra namespace layer to your programs" [ref.] (don't they add a extra local scope?)
- "all the names assigned inside a function definition are put in the local scope (the namespace associated with the function call)."
- "global scope—that is, a namespace in which variables created (assigned) at the top level of the module file live."
*all of the quotes are from learning python 5th edition ch17
Are namespaces in Python the way scopes are implemented? Are they the same thing? Can anyone enlighten me?