syntax glitch with +=
David Eppstein
eppstein at ics.uci.edu
Thu Feb 20 17:45:05 EST 2003
If L and M are lists, L += M is the same as L.extend(M), right?
Nope:
L=[]
def test1():
print L
L.extend([1,2])
def test2():
print L
L += [3,4]
One of these two works, the other produces an error.
Surprised me when I encountered it, anyway...
--
David Eppstein UC Irvine Dept. of Information & Computer Science
eppstein at ics.uci.edu http://www.ics.uci.edu/~eppstein/
More information about the Python-list
mailing list