[newbie] A question about lists and strings

Dave Angel d at davea.name
Fri Aug 10 06:58:47 EDT 2012


On 08/10/2012 06:48 AM, Mok-Kong Shen wrote:
> Am 10.08.2012 12:40, schrieb Chris Angelico:
>
>> 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.
>
> My problem is the following: I have at top level 3 lists and 3 strings:
> lista, listb, listc and stra, strb, strc. I can with a single function
> call change all 3 list values. How could I realize similar changes
> of the 3 string values with a single function call?
>
> Thanks in advance.
>
> M. K. Shen
>
>
Make sure your function returns the values, rather than just trying to
mutate them in place.

def aa(mystring1, mystring2, mystring3):
    mystring1 += "something"
    mystring2 += "otherthing"
    mystring3 += "nobody"
    return mystring1, mystring2, mystring3

str1, str2, str3 = aa(str1, str2, str3)



-- 

DaveA




More information about the Python-list mailing list