Python can return multiple values ββ(in the form of a tuple), eliminating the need to pass values ββby reference.
In your simple example example, even if you were able to apply the same technique, you could not achieve the same result as Python strings that are not mutable.
Thus, your simple example can be translated into Python as follows:
def a(s1, s2): s1 = '{0}test{0}'.format(s1) s2 = '{}({})'.format(s1, s2) return s1, s2 foo, bar = a(foo, bar)
An alternative is to transfer to mutable objects (dictionaries, lists, etc.) and change their contents.
source share