[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: assignment, reference, += and parameter passing



"Fredrik Lundh" <fredrik@pythonware.com> writes:

> Not really: if "a" refers to an object that defines an in-place add
> method, it calls that method.  Otherwise, it uses the corresponding
> binary operation (also a method).
>
> Python itself doesn't distinguish between "mutable" and "immutable"
> objects; behaviour is always defined by the objects themselves.

Yes, I know.  Sorry for explaining it imprecisely.  However, for
builtin types, the effect is the same since only the mutable builtins
can sensibly define such a method.

> (in your example, the design mistake is probably to implement "+="
> for lists to mean "extend".  guess someone got carried away...)

Yes.

-Justin