Page 8 - LN
P. 8

Lesson Note



































                                                               Scope
                                                               a, d, e, X, P- global
                                                               b, c, d, X – local
                                                               global varname-

                                                               allows to modify global
                                                               var in a function













               Lifetime of a variable


               The time for which a variable or name remains in memory is called lifetime of a variable.
               For global variable lifetime is entire program run i.e. as long as the program runs.
               For local variable lifetime is function run i.e. as long as the function runs.
               After the lifetime is over Python releases the memory occupied.

               Namespace in Python
               Namespace is a way to implement scope. In Python, each package, module, class, function and
               method function owns a "namespace" in which variable names are resolved. When a function,
                module or package is evaluated (that is, starts execution), a namespace is created.

               There are four types of scopes, each more specific than the last. A more specific scope can access
               the namespace of a less specific scope, but not the other way around. Here are the four types,
               arranged from most specific to least specific:
   3   4   5   6   7   8   9   10   11