- Does this mean that changing mutable objects inside a function will also change the object in the call area?
Short answer Yes . But keep this: “changing an object” is a broad concept, is a new memory cell assigned? If you redistribute a local variable in the function area, the line with the caller will be split. → more about mutation and assignment
- But if the object is immutable, then changing it inside the function will not affect the object in the call area? Isn’t it in this case different from transmission by value?
This is because an immutable does not change, so the only way to change it is to assign a new memory cell, and thus the split line will be split.
- I am right that the addition! at the end of a function, is it just a convention, but has no semantic meaning in compilation?
Yes you are right.
- What....?
Use deepcopy() instead.
source share