Reference or Value?

andrew cooke andrew at acooke.org
Sun Feb 22 11:37:27 EST 2009


as far as i understand things, the best model is:

1 - everything is an object
2 - everything is passed by reference
3 - some objects are immutable
4 - some (immutable?) objects are cached/reused by the system

andrew


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?
>
> def f1(a):
>     a = 7
>
> b = 3
> f1(b)
> print b
> => 3
>
> Integers are obviously passed by value, lists and dicts by reference.
>
> Is there a general rule?  Some common formulation?
>
>
> Thanks for any hints,
> Torsten.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>





More information about the Python-list mailing list