syntax glitch with +=

Steven Taschuk staschuk at telusplanet.net
Thu Feb 20 19:40:50 EST 2003


Quoth Irmen de Jong:
> David Eppstein wrote:
> > If L and M are lists, L += M is the same as L.extend(M), right?
> > Nope:
  [...]
> You're getting
> UnboundLocalError: local variable 'l' referenced before assignment
> right? This error has nothing to do with a presumed difference
> between extend and +=, in this case.

But that is exactly the difference.  Using += triggers the
"assigned-to variables are local" rule, while using .extend() does
not.

-- 
Steven Taschuk             "The world will end if you get this wrong."
staschuk at telusplanet.net    (Brian Kernighan and Lorrinda Cherry,
                            "Typesetting Mathematics -- User's Guide")





More information about the Python-list mailing list