syntax glitch with +=

Steven Taschuk staschuk at
Fri Feb 21 01:40:50 CET 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

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

More information about the Python-list mailing list