Lecture 72: Global vs Non-local Keywords in Python

Lecture 72: Global vs Non-local Keywords in Python

In Python, global and nonlocal keywords manage variable scope within functions. They dictate whether a variable inside a function refers to a variable outside of it. br Global Keywordbr The global keyword is used to modify a variable defined outside the current function, in the global scope. Without global, any assignment to a variable within a function is assumed to be local to that function.br Nonlocal Keywordbr The nonlocal keyword is used in nested functions to modify a variable in the nearest enclosing scope that is not global.


User: Nafees AI Lab

Views: 10

Uploaded: 2025-05-23

Duration: 05:42

Your Page Title