Object oriented python some personal opinions

When you create an object and assign it to a variable, the variable is only a reference to that object, and not to indicate that the object itself! In other words, just point to the variable name stored in the computer memory of that object. This is called the name of the bound object.

! # / usr / bin / Python 
# - * - = UTF-Coding. 8 - * - 

Print 'simple assignment ----------- -----------' 
the shoplist = [ 'the Apple', 'Mango', 'Carrot', 'Banana'] 
mylist = shoplist # simple assignment only references the variable name 

del shoplist [0] 
del mylist [0] 

Print 'shoplist list:', shoplist 
Print 'mylist list : ', mylist 

Print' is a real slice complete replication: ' 

mylist the shoplist = [:] 

del mylist [0] 

Print' list of the shoplist: ', the shoplist 
Print' mylist list: ', mylist

The output is:

----------- ----------- simple assignment 
shoplist list: [ 'carrot', 'banana '] 
mylist list: [ 'carrot', 'banana '] 
complete slice is a true copy: 
shoplist list: [ 'Carrot', 'Banana'] 
mylist list: [ 'banana']

Obviously, the general reference only binding name, and only complete slice is replicated in the true sense. So we must consider the simple reference to whether you can change, because the operation may affect the source object.

Guess you like

Origin www.cnblogs.com/ngbjng/p/12015075.html