1) Value transfer problem
Whether the python is "value passing" or "reference passing" depends primarily on the object being mutable. 1) Function Reference: • Basic data type: int, float, str; Ganso is a non-mutable object, and a copy of "original value" is passed. The list, dictionary, class, class instances are mutable objects, and the variable copy (a=b) in the variable copy Python is passed as the same as Kind of truth, immutable objects are actually copied, whereas mutable objects simply pass a "reference" example: a = 1 B = A, at which time changing the value of a does not change the value of B
2) Memory mechanism
1) variable values are stored in memory • Basic data types: int, str, float, etc., the same value is assigned to different variables, the memory address is consistent; • Lists, Ganso, dictionaries, the same values are assigned to different variables, the memory address is an example of inconsistency: a = 1 b = 1 ID (a) =id (b) This is a = [up] b = [up] ID (a) = ID (b) This is not true 2) memory management mechanism • Reference count: Trace objects in memory when an object is created, a reference count is created, and when the object is no longer needed, the object's reference count is 0 o'clock, and it is garbage collected. • Memory pool: not currently discussed
This article from "Kong Love to Eat fish" blog, declined reprint!
Python value delivery problem and memory management mechanism