Question #606

Which keyword prevents changing variables in a nested function?

The keyword nonlocal indicates that a variable inside a nested function does not belong to the scope of that inner function but to the function encapsulating it. ``` def myfunc1(): x = "John" def myfunc2(): x = "hello" myfunc2() return x print(myfunc1()) ``` will output: ``` >>>John ``` The keyword global is different. It indicates that the scope of a variable is defined at the module level. (

Comment on Disqus:

Comment on Twitter:

Question difficulty: πŸ”΅πŸ”΅πŸ”΅πŸ”΅πŸ”΅