August 2018
Intermediate to advanced
332 pages
9h 12m
English
The first rule in Python is that all arguments are passed by a value. Always. This means that when passing values to functions, they are assigned to the variables on the signature definition of the function to be later used on it. You will notice that a function changing arguments might depend on the type arguments—if we are passing mutable objects, and the body of the function modifies this, then, of course, we have side-effect that they will have been changed by the time the function returns.
In the following we can see the difference:
>>> def function(argument):... argument += " in function"... print(argument)... >>> immutable = "hello">>> function(immutable)hello in function>>> mutable = list("hello") ...