On Dec 7, 9:54 am, m...@pixar.com wrote:

> How can I make a "var" parm, where the called function can modify
> the value of the parameter in the caller?
>
> def f(x):
>     x = x + 1

Short ansver:

You can modify function parameters if they are mutable. If they are
immutable any attempt to modify the parameter will trigger a copy.

You cannot modify parameters by rebinding. x = x + 1 is a rebinding. x
+= 1 is not.

If you need to modify immutable parameters or do the modification by
rebinding, pass the variable back. Python allows multiple return
values.
















--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to