Augument assignment versus regular assignment
Boris Borcic
bborcic at gmail.com
Wed Jul 19 09:10:05 EDT 2006
Antoon Pardon wrote:
> The language reference doesn't talk about objects. And IMO you
> should be carefull if you want to use the word "object" here.
> In the line: "foo += 1", you can't talk about the object foo,
> since foo will
possibly
> be bound to a different object after the assignment
> than it was bound to before.
witness
>>> class Foo(list) :
def __iadd__(self,other) :
self.append(other)
return self
>>> bar = foo = Foo()
>>> foo += 1
>>> foo is bar
True
>>> foo
[1]
while of course
>>> bar = foo = 0
>>> foo += 1
>>> foo is bar
False
Best, BB
--
"On naît tous les mètres du même monde"
More information about the Python-list
mailing list