KnowledgeBoat Logo
|

Computer Science

Assertion (A): Variables declared inside a function are local to that function by default.

Reasoning (R): A function can access global variables if they are explicitly declared with the global keyword inside the function.

Python Functions

1 Like

Answer

Both A and R are true, and R is the correct explanation of A.

Explanation — By default, variables declared inside a function are local to that function, meaning their scope is limited to the function itself. However, a function can access and modify global variables only if they are explicitly declared with the global keyword inside the function. Otherwise, the function will treat the variable as local.

Answered By

2 Likes