I read several other SOs ( PythonScope and global global values ββare not needed), but nothing seems to explain as clearly as I would like, and I am having problems with mental sifting, regardless of whether PyDocs tells me the answer to my question
myList = [1]
def foo():
myList = myList + [2, 3]
def bar():
myList.extend([2, 3])
def baz():
myList += [2, 3]
Now it is clear,
>>> foo()
UnboundLocalError
and
bar()
myList
but then
>>> baz()
UnboundLocalError
I thought, however, that such things as +=are implicitly called method statements, in this case extend(), but the error implies that for some reason it does not actually consider +=how extends(). Is this consistent with how Python parsing should work?
, , -, . , += . , , , - ( , ):
myList = range(50000000)
myList += [0]
myList = myList + [1]
, += extend().
- ( ...), , , myList baz() , += extend(), ?