+ 1
Nonlocal Keyward Error, how to solve?
def myfunc1(): x = "John" def myfunc2(): nonlocal x x = "hello" myfunc2() return x
7 Antworten
+ 5
Levon Yeghiazaryan, which python version do you use?
+ 5
Levon Yeghiazaryan Yes, that explains a lot 😏 Nonlocal will only work with python 3
+ 2
Try running your code in the Code Playground. It works fine for me.
+ 2
2.7, I guess the reason of your question.)
+ 1
Thank you, I will do.
0
It works normally for me, it returns 'hello' when called. It doesn't raise any error.
0
It raises invalid syntax on nonlocal x