[Tutor] changing name value with function return

Timo timomlists at gmail.com
Tue Oct 30 18:40:21 CET 2012


Op 30-10-12 17:56, richard kappler schreef:
> If I have a variable and send it's value to a function to be modified 
> and returned, how do I get the function return to replace the original 
> value of the variable?
>
> Example:
>
> import random
>
> x = 50
>
> def rndDelta(x):
>     d = random.uniform(-10, 10)
>     x = x + d
>     return x
>
> When I call rndDelta, it functions as intended, I get a return that is 
> x adjusted by some random value. This, however, I know does not 
> actually change x. Let's say I call randDelta(x) and it returns 
> 42.098734087, if I then type x, I still get 50. I want x to now be 
> 42.098734087.
>
What about declaring the return value as x again?

x = randDelta(x)

Timo

> regards, Richard
>
>
>
> -- 
>
> sic gorgiamus allos subjectatos nunc
>
>
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor



More information about the Tutor mailing list