17.10 Side Effects
So far, we have skillfully avoided this issue, but you should always keep in mind that side effects can always occur when an instance of a mutable data type, such as a list or a dictionary, is passed as a function parameter.
In Python, a function call doesn’t create any copies of the instances passed as arguments, but works internally in the function with references to the arguments. This method of parameter passing is called call by reference. This is in contrast to the call by value principle, which works on copies of the arguments within the function. The latter variant, which is supported by many other programming languages, is free of side effects, but slower due to the copy process.
Consider the following example: ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access