Python 3 Learning Day eighth--shades of copy and functions

Source: Internet
Author: User
Tags shallow copy

The eighth section of Python Learning

Write this blog to motivate yourself and share your experiences and issues with others.

First, study notes

1. Depth copy

Shallow copy--copy.copy () #shallow copy

Use B = a.copy () so that B is a copy of A. All features of light copy are included

    features : Only copy "one layer" of this layer refers (if a[[1, 2], 3, 4]) so, b copy can only modify b[1], b[2] value of CAI does not affect the value of a, if B modifies the value of the element in the list, then it is the value of a element list Modified (memory mechanism). This is the shallow copy.

Deep copy--copy.deepcopy

    features : Copy is completely independent after a = Copy.deepcopy (b) But you must import copy "import copy" before using deep copy

2. Set (set)--combine different elements together

How the ① collection is created

      S1 = [' Liufeiduo ', ' Zuishuai ']

s = Set (S1)

The ② collection object is hashed and can be used as a dictionary key

③ the value of the collection: For loop iteration, iterator

④ mutable set: Set () the set () is itself a non-hash key that cannot be used as a dictionary to add or delete an immutable collection of elements: Frozenset () is the opposite of the former

Access to the ⑤ collection

The collection itself is unordered and cannot be accessed by slicing or creating an index, only looping through, or using in and not

Update for ⑥ Collection

S.add () Add an element

      S.updata () Each element is added to the sequence

S.remove (' Liufeiduo ') removes the selected element

S.pop () Random deletion

S.clear () emptying the collection

 

    Features: unordered, non-repetitive

3. Functions (emphasis)

① concept

      

Python 3 Learning Day eighth--shades of copy and functions

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.