Weird lambda rebinding/reassignment without me doing it

ssecorp circularfunc at gmail.com
Thu Jul 10 22:46:44 CEST 2008


>>> def mod(x,y):
	return x.append(y)

>>> mod([1,2],3)
>>> k=[1,2,3]
>>> k
[1, 2, 3]
>>> l = mod(k,4)
>>> l
>>> k
[1, 2, 3, 4]
>>> l
>>> k==l
False
>>> mod(k,5)
>>> k
[1, 2, 3, 4, 5]
>>> mod(l,4)

Traceback (most recent call last):
  File "<pyshell#29>", line 1, in <module>
    mod(l,4)
  File "<pyshell#18>", line 2, in mod
    return x.append(y)
AttributeError: 'NoneType' object has no attribute 'append'
>>> l
>>> l=k
>>> l
[1, 2, 3, 4, 5]
>>> i=mod(k,1)
>>> i
>>>

same stuff but i dont find this intuitive.



More information about the Python-list mailing list