All Courses

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

By Manerushi149@gmail.com, a month ago
  • Bookmark
0

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

Keyword
"nonlocal"
Python 3
Python
1 Answer
0
Goutamp777

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

Webinars

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