Python Frequently Asked Questions, Release 3.9.5 Chapter 2. Programming FAQ 14 (continues on next page) [1, 2, 3] is equivalent to$_{a_list.extend([1, 2, 3])}$ and mutates$_{a_list}$ , whereas$_{some_tuple}$ += (1, 2, 3) and some_int += 1 create new objects). In other words: If you want to know if two variables refer to the same object or not, you can use the is operator, or the built-in function id() . Remember that arguments are passed by assignment in Python. Since assignment just creates references to objects, there’s no alias between an argument name in the caller and callee, and so no call-by-reference per se. You can achieve the desired effect in a number of ways. 1) By returning a tuple of the results: >>>def func1 (a, b): ... a ='new-value ' # a and b are local names ... b =b +1 # assigned to new objects ... return a, b # return new values ... >>> x, y='old-value ',99 >>> func1(x, y) ('new-value', 100) >>>def func2 (a): ... a[0] ='new-value ' # 'a' references a mutable list ... a[1] =a[1] +1 # changes a shared object ... >>> args =['old-value ',99 ] >>> func2(args) >>> args ['new-value', 100] >>>def func3 (args): ... args['a'] ='new-value ' # args is a mutable dictionary ... args['b'] =args['b'] +1 # change it in-place ... >>> args ={ 'a':'old-value ','b':99 } >>> func3(args) >>> args {'a': 'new-value', 'b': 100} >>>classNamespace : ... def __init__ (self,/,**args): ... for key, value in args.items(): ... setattr(self, key, value) • If we have a mutable object ( list , dict , set , etc.), we can use some specific operations to mutate it and all the variables that refer to it will see the change. • If we have an immutable object ( str , int , tuple , etc.), all the variables that refer to it will always see the same value, but operations that transform that value into a new value always return a new object. 2.2.10 How do I write a function with output parameters (call by reference)? This is almost always the clearest solution. 2) By using global variables. This isn’t thread-safe, and is not recommended. 3) By passing a mutable (changeable in-place) object: 4) By passing in a dictionary that gets mutated: 5) Or bundle up values in a class instance: