modifying string objects

Andrew Koenig ark at research.att.com
Thu Jun 13 11:57:13 EDT 2002


Uwe> strings are immutable in python. so what do i do if i need to pass a 
Uwe> function a string as parameter and need it to be modified within the 
Uwe> function so that changes are reflected outside of the function body?

Uwe> f.e. a class constructor must return None

Uwe> class foobar:
Uwe>   def __init__(text):
Uwe>     text = text[-1]			#this is what i actually want

Instead of a string, use a one-element list:

       def __init__(text):
         text[0] = text[0][-1]

-- 
Andrew Koenig, ark at research.att.com, http://www.research.att.com/info/ark



More information about the Python-list mailing list