Computer Science
What is the order of resolving scope of a name in a Python program ?
- B G E L
- L E G B
- G E B L
- L B E G
Python Functions
1 Like
Answer
L E G B
Reason — When you access a variable from within a program or function, python follows name resolution rule, also known as LEGB rule. When python encounters a name (variable or function), it first searches the local scope (L), then the enclosing scope (E), then the global scope (G), and finally the built-in scope (B).
Answered By
2 Likes
Related Questions
Carefully observe the code and give the answer.
def function1(a): a = a + '1' a = a * 2 >>>function1("hello")
- indentation Error
- cannot perform mathematical operation on strings
- hello2
- hello2hello2
What is the result of this code ?
def print_double(x): print(2 ** x) print_double(3)
- 8
- 6
- 4
- 10
Which of the given argument types can be skipped from a function call ?
- positional arguments
- keyword arguments
- named arguments
- default arguments
Fill in the blanks:
A _________ is a subprogram that acts on data and often returns a value.