Pass by reference or by value?

Dan Bishop danb_83 at yahoo.com
Fri Jul 13 19:31:50 EDT 2007


On Jul 13, 2:10 pm, Robert Dailey <rcdai... at gmail.com> wrote:
> Hi,
>
> I noticed in Python all function parameters seem to be passed by
> reference. This means that when I modify the value of a variable of a
> function, the value of the variable externally from the function is
> also modified.

Python is pass-by-value.  It's just that all values are implicit
"pointers".  Much like Java except without a distinction between
primitives and objects.

> Sometimes I wish to work with "copies", in that when I pass in an
> integer variable into a function, I want the function to be modifying
> a COPY, not the reference. Is this possible?

Typically, there's no reason to make a copy of an immutable object.
But if you want to copy things, take a look at the "copy" module.




More information about the Python-list mailing list