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