- Home
- Class - 12 CBSE Computer Science — Assertion Reason Type Questions
Assertion. A function declaring a variable
Class - 12 CBSE Computer Science — Assertion Reason Type Questions
Assertion. A function declaring a variable having the same name as a global variable, cannot use that global variable.
Reason. A local variable having the same name as a global variable hides the global variable in its function.
Answer
(a)
Both Assertion and Reason are true and Reason is the correct explanation of Assertion.
Explanation
Inside a function, you assign a value to a name which is already there in global scope, Python won't use the global scope variable because it is an assignment statement and assignment statement creates a variable by default in current environment. That means a local variable having the same name as a global variable hides the global variable in its function.