function that modifies a string

greenflame alikakakhel at yahoo.com
Sun Jul 9 23:49:50 EDT 2006


I want to make a function that does the following. I will call it
thefunc for short.

>>> s = "Char"
>>> thefunc(s)
>>> s
'||Char>>'

I tried the following

def thefunc(s):
    s = "||" + s + ">>"

The problem is that if I look at the string after I apply the function
to it, it is not modified. I realized that I am having issues with the
scope of the variables. The string in the function, s, is local to the
function and thus I am not changing the string that was inputed, but a
copy. I cannot seem to figure out how to get what I want done. Thank
you for your time.




More information about the Python-list mailing list