This article is mainly for everyone in-depth analysis of the Python3 list of three ways to copy, with a certain reference value, interested in small partners can refer to
# Auther:aaron fannames = ["Aaron", "Alex", "James", "Meihengfan"] #复制一份列表 # Shallow copy (note that this is only a shallow copy, can only copy the first layer of the list of things, if the list has a layer of list , then that layer of the list just points to the physical address past, but did not copy it over) #在day2第9个视频, there is a detailed explanation of this shallow copy of the role, here no longer detailed comment person = ["Name", ["Saving", 100]] "" Shallow copy method has 3 kinds: P1 = Person.copy () p1 = Person[:]p1 = List (person) "P1 = Person[:]p2 = Person[:]print (p1) print (p2) p1[0] =" Alex "p2[0] =" Feng Jie "Print (p1) print (p2) #注意第二层列别中的值同时变了, where the joint account to understand the role of shallow copy p1[1][1] = 50print (p1) print (p2) #深复制 (this copy is a complete replication, You can also copy the list inside the list, rather than just pointing to an address in the past. Import Copynames2 = copy.deepcopy (names)