World's Best AI Learning Platform with profoundly Demanding Certification Programs
Designed by IITians, only for AI Learners.
Designed by IITians, only for AI Learners.
New to InsideAIML? Create an account
Employer? Create an account
The keyword "nonlocal" in Python 3 is used to access a variable defined in an outer, but not global, scope in a function. It is similar to the "global" keyword, but instead of accessing a global variable, it allows the function to access a variable in an outer scope. This can be useful when working with nested functions that need to modify a variable in an outer scope, but not a global scope. Without the "nonlocal" keyword, the variable would be treated as a local variable within the nested function.