Surprise Me!

Lecture 72: Global vs Non-local Keywords in Python

2025-05-23 10 Dailymotion

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 Keyword<br />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 Keyword<br />The nonlocal keyword is used in nested functions to modify a variable in the nearest enclosing scope that is not global. It allows inner functions to modify variables in the outer (non-global) function's scope

Buy Now on CodeCanyon