On Sep 19, 9:59 pm, Peng Yu <pengyu...@gmail.com> wrote:
> Hi,
>
> I know that strings or numbers are immutable when they passed as
> arguments to functions. But there are cases that I may want to change
> them in a function and propagate the effects outside the function. I
> could wrap them in a class, which I feel a little bit tedious. I am
> wondering what is the common practice for this problem.
>
> Regards,
> Peng

Python strings and numbers are always immutable, not just when passed
as arguments.

"propagate the effects outside the function" is a little vague.

You can return new data objects (like str.lower() etc.. do) or you can
wrap them in a namespace (a dict or class instance) or you can pass a
list object that contains the string or int or whatever, and your
functions can replace the values in the dict/instance/list.

HTH,
~Simon
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to