The purpose of parameters is to provide the function with the necessary input data. Changing the value of the parameter inside the function normally has no effect on its value outside the function:
def subtract(x1, x2): z = x1 - x2 x2 = 50. return z a = 20. b = subtract(10, a) # returns -10 a # still has the value 20
This applies to all immutable arguments, such as strings, numbers, and tuples. The situation is different if mutable arguments, such as lists or dictionaries, are changed.
For example, passing mutable input arguments to a function and changing them inside the function can change them outside the function too:
def subtract(x): z = x[0] - x[1] x[1] = 50. return z a = [10,20] b = subtract(a) # returns -10 a # is now [10, 50.0]
Such a function misuses its arguments to return results. We strongly dissuade you from such constructions and recommend that you do not change input arguments inside the function (for more information...