Beginnger Question

Matthias Hanitzsch Matthias.Hanitzsch at dynamic.de
Tue Apr 9 10:42:59 EDT 2002


Dennis wrote:

> x = 2
>
> def wrong(num):
>     return num + 1
>
> print wrong(x)
> print wrong(x)
>
> I cannot figure out why this (simplified) program won't increment x
> and produce 3 and 4.

Hi,
this is "call by value", that means that the parameter num of your
function will get the VALUE of the variable x.
Then num is incremented and returned.
The variable x is not changed, as you never write to it. You just
take its value.

HTH,
Matthias




More information about the Python-list mailing list