var or inout parm?

Colin J. Williams cjw at ncf.ca
Sun Dec 7 14:20:41 CET 2008


mh at 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
> 
> n = 1
> f(n)
> # n should now be 2
> 
> Many TIA!!
> Mark
> 
> 

Why not run it and see?

Your function returns None.

The function in effect takes a copy of 
n.  n is not changed.

Colin W.



More information about the Python-list mailing list