can someone explain?

Gerrit Holl gerrit at nl.linux.org
Mon Feb 17 11:55:57 EST 2003


Pablo schreef op maandag 17 februari om 17:41:59 +0000:
> def increase(val):
>   val +=1
> 
> k = 0
> increase(k)
> print k

> 
> What should I do to make k equal 1 in that case? increase() changes
> only a copy, how to make it change passed variable?

 17 >>> k=0
 18 >>> def inc():
 18 ...  global k
 18 ...  k+= 1
 18 ...
 19 >>> inc()
 20 >>> print k
1
 21 >>> inc()
 22 >>> print k
2

yours,
Gerrit.

-- 
Asperger Syndroom - een persoonlijke benadering:
	http://people.nl.linux.org/~gerrit/
Het zijn tijden om je zelf met politiek te bemoeien:
	http://www.sp.nl/





More information about the Python-list mailing list