Reference or Value?
Steven D'Aprano
steven at REMOVE.THIS.cybersource.com.au
Sun Feb 22 21:43:59 EST 2009
On Sun, 22 Feb 2009 16:13:02 +0100, Torsten Mohr wrote:
> Hi,
>
> how is the rule in Python, if i pass objects to a function, when is this
> done by reference and when is it by value?
Never, and never.
> Integers are obviously passed by value, lists and dicts by reference.
Your error is assuming that pass-by-value and pass-by-reference are the
only two possibilities, consequently you are misinterpreting what you see.
Python uses the same evaluation strategy regardless of the type of object
being passed. Sometimes that strategy looks something like pass-by-value,
and sometimes it looks something like pass-by-reference, but in fact it
always behaves consistently no matter what object you use.
> Is there a general rule? Some common formulation?
http://en.wikipedia.org/wiki/Evaluation_strategy#Call_by_sharing
http://effbot.org/zone/call-by-object.htm
--
Steven
More information about the Python-list
mailing list