Vamei Source: Http://www.cnblogs.com/vamei Welcome reprint, Please also keep this statement. Thank you!
Original chain: http://www.cnblogs.com/vamei/archive/2012/07/10/2582795.html
Notes:
1 #19th talk about dynamic types2 3 #There is a special kind of object that is used to store data. Include: numbers, strings, tables, dictionaries4 #c is a variable, and Python is the object5 #objects are stored in memory and cannot be directly exposed to6 #we are usually in the program object name, is a reference to this object, the object and the reference is separated7 8A = 3#Assign the Integer object 3 in memory to the variable A, object a9 TenA =' at'#set the object ' at ' in memory, reference A to ' at ' One Print(a) A - #at this point, Object 3 does not have a reference to it, and Python automatically destroys it, freeing the memory - theA = 5 -b =a -A = a + 2 - Print(a) + Print(b) - #B = A references B to the object that refers to a + #The third sentence is to re-assign a value to a. A atL1 = [A] -L2 =L1 -L1 = 1 - Print(L2) - - #does not affect the L2, is still list[1,2,3] in - #Special Cases toL1 = [A] +L2 =L1 -L1[0] = 5 the Print(L1) * Print(L2) $ Panax Notoginseng #will find that index 0, the first element of list, has changed, and L1 L2 has changed. - #list is a reference to many objects, l1[0] is 1, l1[1] is 2 the #It just changed an element operation, so the big object reference changed. + A the #The list dict can change its own object, called a mutable data object, by referencing the element. + #numbers and STR can only change the reference point, which is called the immutable data object - $ #tuples can be referenced, but tuples themselves are not updatable and immutable data Objects $ - - the - Wuyi #the parameter passing of function from the view of dynamic type the - deff (x): Wux = 100 - Print(x) About $A = 1 -F (a)#function f (x) executed - Print(a) - A #F (a) is + #print (a) output is 1 the - #The parameter x is a new reference to the object referred to by a. $ #If the argument is an immutable object, a and X are independent of each other and the operation on X does not affect a the the the deff (x): theX[0] = 100 - Print(x) in theA = [A.] the F (a) About Print(a) the the #like above, a mutable object is passed, and a reference to the original list changes after the change .
Hand drawing two pictures
Immutable data types
Variable data types
Python Learning notes (19) dynamic type