You are writing a nested function, and you want to modify a variable from the outer function. However, you don't want this change to affect the global scope. How can you achieve this?

  • Use the global keyword
  • Use the local keyword
  • Use the nonlocal keyword
  • Use the private keyword
To modify a variable from an outer function without affecting the global scope, use the 'nonlocal' keyword. It allows you to access and modify the variable in the closest outer scope.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *