Beginnger Question
Torben Lauritzen
batman at daimi.au.dk
Tue Apr 9 11:32:04 EDT 2002
Matthias Hanitzsch <Matthias.Hanitzsch at dynamic.de> writes:
> 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
>
As I see it, num is not incremented, before it is returned. So, even
if it had been a 'call by reference', x would not increase.
--
- Torben
More information about the Python-list
mailing list