Three ways to python3 a list of shades

Source: Internet
Author: User
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)
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.