Pointers in Python
bruno.42.desthuilliers at websiteburo.invalid
Tue Apr 27 15:58:29 CEST 2010
Anton Shishkov a écrit :
> Hi, I can't figure out how can I change the variable type in function.
> In C I could do that easily by changing pointer.
Others already answered on this. Now, the real question is : why to you
want to do such a thing ?
Of one the most common use case for this idiom in C is to workaround the
lack of multiple return values, so your function returns an error code
*and* "sets" a value thru the pointer. This idiom makes no sense in
Python since we have exception handling. FWIW, other use case are
usually solved by tuple unpacking, ie:
def fun(a, b):
return a+b, a*b
sum_, prod = fun(5, 4.5)
More information about the Python-list