[Tutor] Possible to change values of scalar function parameters?

Kent Johnson kent37 at tds.net
Tue Feb 17 18:34:50 CET 2009


On Tue, Feb 17, 2009 at 11:57 AM,  <python at bdurham.com> wrote:
> Is there a way to change values of scalar function parameters? I know you
> can change the values of parameters if the parameter is a mutable type like
> a list, but is there a way to update the value of scalar parameters of type
> integer or string?
>
> Simple example: Is there a way to have the following function update its
> changeme parameter in a 'call by reference' manner?
>
>>>> def test1( changeme ):
>     changeme = 'Changed!'

No, not a simple way at least. Possibly you can do it with hackery
involving stack frames but I wouldn't recommend that. Either pass the
values in some kind of container (list, dict, class instance) or
return the new value and assign it in the caller.

Kent


More information about the Tutor mailing list