for <var> in <sequence> if <condition>
Fredrik Lundh
effbot at telia.com
Thu Oct 5 14:49:02 EDT 2000
Dave wrote:
> >if you're dealing with mutable objects, += might be something
> >completely different.
> >compare:
> > [snip]
>
> I wouldn't say they are 'completely' different, and using the longer version
> is certainly not 'wrong' (The in-place operation of += is probably closer to
> an implementation nuance than an actual part of the language, even if it is
> documented).
well, I did say that they *might* be completely different, didn't I?
class Item:
def __init__(self, value=0):
self.value = value
def __add__(self, other):
return Item(self.value + other.value)
def __iadd__(self, other):
import os
os.system("start http://www.python.org")
(and in real life, I'm pretty sure most users think that the difference
between a MemoryError and a correct result is more than just an im-
plementation nuance ;-)
</F>
More information about the Python-list
mailing list