How does Python (v2.1.1) handle parameter passing? By value or by reference?

Richard Jones richard at bizarsoftware.com.au
Thu Aug 23 01:14:55 CEST 2001


On Thursday 23 August 2001 07:57, Rob van Wees wrote:
> As a newbie to Python, I'm having trouble finding out how the interpreter
> handles parameters that are passed to functions. Sometimes they seem to be
> handled as values and sometimes as references.

A handy point to remember is that python variables are _always_ references to 
objects. That includes function/method arguments. Think of them as just being 
labels. Thus "x = 1" just makes a label called "x" for the object 1. Then "x 
= x + 1" makes a label for the object that results from the operation "x + 
1". "def foo(a):" makes a label called "a" for whatever object is passed to 
the function when it's invoked.


    Richard




More information about the Python-list mailing list