Pascal "var parameter" in Python -


in pascal have var parameters, , functions can change parameter values new values:

procedure a(var s1, s2: string); begin   s1:= s1+'test'+s1;   s2:= s1+'('+s2+')'; end; 

does python have such feature? can change string parameter inside method, or must use return , assign variable later?

python can return multiple values (in form of tuple), obsoleting need pass values reference.

in simple sample case, if able apply same technique, not achieve same result python strings not mutable.

as such, simple example can translated python as:

def a(s1, s2):     s1 = '{0}test{0}'.format(s1)     s2 = '{}({})'.format(s1, s2)     return s1, s2  foo, bar = a(foo, bar) 

the alternative pass in mutable objects (dictionaries, lists, etc.) , alter contents.


Comments