Python 3.0 nonlocal statement

Rob Williscroft rtw at
Tue Jan 6 17:46:02 CET 2009

Matimus wrote in news:2a3d6700-85f0-4861-84c9-9f269791f044 in comp.lang.python:

> On Jan 6, 5:31 am, Casey <Casey... at> wrote:
>> In PEP 3104 the nonlocal statement was proposed and accepted for
>> implementation in Python 3.0 for access to names in outer scopes.  The
>> proposed syntax included an optional assignment or augmented
>> assignment to the outer name, such as:
>> nonlocal x += 1
>> This syntax doesn't appear to be supported in the 3.0 implementation.
>> My question is: was this intentional or was it missed in the initial
>> release?  If it was intentional, is there any plan to support it in a
>> later 3.x release?  I realize it is a very small convenience feature
>> but I have already come across a couple of cases where I use nested
>> functions where it does make the code seem a little cleaner.
>> Regards, Casey
> `nonlocal` should behave just like `global` does. It doesn't support
> that syntax either. So, yes it was intentional. No, there probably is
> no plan to support it in a later release.
> Matt

A shorthand form is also permitted, in which nonlocal is prepended to an 
assignment or augmented assignment:

nonlocal x = 3

The above has exactly the same meaning as nonlocal x; x = 3. (Guido 
supports a similar form of the global statement [24].)


Searching (AKA googling) for: nonlocal
leads to:


More information about the Python-list mailing list