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

Re: assignment, reference, += and parameter passing



"Pixel" wrote:

> > You misunderstand Python's assignment and parameter passing model.
> >
> > It is always "pass by object reference".
>
> oops. fixed
>
> http://merd.net/pixel/language-study/various/assignment/result

    pass-by-object-ref
    "a = b"  "a" is a new object
    "a += b" it depends:
        for int/strings: "a" is a new object
        for lists: modify the existing object "a"
            (implies a+=b different from a=a+b)

still misleading.  in "a = b", "a" isn't a "new object", it's
another name for the same object.

and "a += b" depends on if/how "a" defines "add some-
thing to self".  ints and strings don't, lists do.

reading this might also help:

    http://effbot.org/guides/python-objects.htm

</F>