Page 9 - LN
P. 9

Lesson Note













               The local scope. The local scope is determined by whether you are in a class/function definition or
               not. Inside a class/function, the local scope refers to the names defined inside them. Outside a
               class/function, the local scope is the same as the global scope.
               The non-local scope. A non-local scope is midways between the local scope and the global scope,
               e.g. the non-local scope of a function defined inside another function is the enclosing function itself.
               The global scope. This refers to the scope outside any functions or class definitions. It also known as
               the module scope.
               The built-ins scope. This scope, as the name suggests, is a scope that is built into Python. While it
               resides in its own module, any Python program is qualified to call the names defined here without
               requiring special access.



               LEGB Rule
               For any memory reference during the program execution, Python follows LEGB rule to find the
               namespace/environment of the variable. Rule is:
                  i)   First it checks Local namespace if found uses it, if not
                 ii)   Then checks Enclosed namespace if found uses it, if not
                 iii)   Then checks Global namespace if found uses it, if not
                 iv)   Then checks Built-in namespace if found uses it, else reports error.

























               Mutable/Immutable Properties Of Passed Data Objects

               Passed data objects/variable containers in Python are memory reference, they point to memory
               location where values are stored.

               Depending on the value of the mutable and immutable type the value change happens in Python for
               a passed data objects.
   4   5   6   7   8   9   10   11