Variables Scope In Python

Variables declared inside a function are local to that function.


Variable declared outside a function can be accessed anywhere.


Use the global keyword to change it.


Inner function can access variable from the outer function.


The nonlocal keyword allows modifying a variable in the outer (enclosing) function.

Leave a Comment