changing a value of a variable

Delaney, Timothy tdelaney at avaya.com
Tue Jan 29 19:43:41 EST 2002


> From: marcinm at finisar.com [mailto:marcinm at finisar.com]
> 
> How to write a python program that accomplishes the same thing as the
> C program below.
> 
> void assign(int *x)
> {
>   *x = 1;
> }
> 
> int main(void)
> {
>    int n = 0;
> 
>    /* n == 0 */
>    assign(n);
>    /* n == 1 */
> 
>    return 0;
> }

In general, you don't. The above is not a pythonic idiom.

http://www.python.org/doc/current/tut/tut.html
http://www.python.org/doc/Newbies.html

The normal method is to rebind the return value of the function to the name
(in this case, 'n'). The above links will let you understand what the
previous sentence means.

Tim Delaney




More information about the Python-list mailing list