On Fri, Aug 10, 2012 at 8:31 PM, Mok-Kong Shen
<mok-kong.s...@t-online.de> wrote:
> This means there is no way of modifying a string at the top level
> via a function, excepting through returning a new value and assigning
> that to the string name at the top level. Please again correct me, if
> I am wrong.

Yes, but you can (ab)use a one-element list as a pointer.

>>> foo=["Hello"]
>>> def mutate(ptr):
        ptr[0]="World"
        
>>> mutate(foo)
>>> print(foo[0])
World

But it's probably worth thinking about exactly why you're wanting to
change that string, and what you're really looking to accomplish.
There may well be a better way.

Chris Angelico
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to