var or inout parm?
Chris Rebert
clp at rebertia.com
Sun Dec 7 04:05:55 EST 2008
On Sun, Dec 7, 2008 at 12:54 AM, <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?
Not directly possible or encouraged. You can emulate it by sticking
the value in a container object (e.g. list) though:
def f(x):
x[0] += 1 #non-augmented assignment would work too
n = [1]
f(n)
print n[0] #==> 2
Cheers,
Chris
--
Follow the path of the Iguana...
http://rebertia.com
>
> def f(x):
> x = x + 1
>
> n = 1
> f(n)
> # n should now be 2
>
> Many TIA!!
> Mark
>
>
> --
> Mark Harrison
> Pixar Animation Studios
> --
> http://mail.python.org/mailman/listinfo/python-list
>
More information about the Python-list
mailing list