1.

What is the meaning of scope in python.

Answer»

The scope defines the accessibility of the python object. To access the particular variable in the code, the scope must be defined as it cannot be accessed from anywhere in the program. The particular coding region where variables are visible is known as scope. Variables are not visible to the entire code; their visibility can be restricted. Scope verifies which variable can be ‘Seen’. The scope defines the set of rules which tell us how and where a variable can be searched. The variable is searched either to retrieve a value or for assigning value. The namespace is the unique identification of the variable or the method. Namespace tells the python interpreter about the name of the object and the location from where it is trying to access it.

The Namespaces are searched for scope resolution according to the LEGB rule. The LEGB stands for :L: Local, E: Enclosed, G: Global, B: Built-in. The sequence of LEGB is important. The variable is first searched in Local, followed by Enclosed, then global and finally built-in.



Discussion

No Comment Found

Related InterviewSolutions