Computer Science
Answer
When we 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).
Related Questions
How are the following two statements different from each other?
(a) import math
(b) from math import*
What is the utility of math module?
A program having multiple functions is considered better designed than a program without any functions. Why ?
Write a module called calculate_area() that takes base and height as an input argument and returns an area of a triangle as output. The formula used is
Triangle Area = 1⁄2 * base * height