[Tutor] nonlocal variables

Vladislav Vorobyov vorobyov.vladislav at gmail.com
Tue Feb 23 13:38:25 CET 2010


#!/usr/bin/python
def func_outer():
        x = 2
        print('x is', x)
        def func_inner():
                nonlocal x
                x = 5
        func_inner()
        print('Changed local x to', x)

func_outer()

Output:
File "nonlocal_var.py", line 6
    nonlocal x
             ^
SyntaxError: invalid syntax
Why? Cannon find in google it.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100223/b49bc648/attachment.html>


More information about the Tutor mailing list