All Courses

What is the role or function of the keyword "nonlocal" in Python 3?

By, a month ago
  • Bookmark

What does the Keyword "nonlocal" do in Python 3?

Python 3
1 Answer

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.

Your Answer


Live Masterclass on : "How Machine Get Trained in Machine Learning?"

Mar 30th (7:00 PM) 516 Registered
More webinars

Related Discussions

Running random forest algorithm with one variable

View More