By value or by reference?

Jeremy Bowers jerf at jerf.org
Mon Oct 18 17:06:27 EDT 2004


On Mon, 18 Oct 2004 15:30:54 +0000, Riccardo Rossi wrote:

> Hi all!
> 
> How does Python pass arguments to a function? By value or by reference?

Summarizing all of the arguments, it is "Pass by reference, by value".

The functions receive copies of the references, but the function receives
a new reference by value, not "the same reference" as it is in C++. 

def something(a):
    a = 11

immediately discards the passed-in reference with no affect on the caller.

This is never correct in Python:

somefunction() = "some value"

This is sort of "because" of the way Python bind names, and in another
sense, is the *cause* of the Python name binding behavior :-)



More information about the Python-list mailing list