---restore content starts---
1. Collection creation
There are two ways to create a comparison list, a tuple, a dictionary, and only one way to create a collection
1 s = set ("Alex Li")
2. The collection object is a set of unordered, hashed values---the collection member is immutable (cannot use a list, the dictionary is a member of the collection), and the collection itself is mutable
1 li = [[],'a','b']2 S9 = Set (LI)3print(S9)
This code will error: S9 = Set (LI)
Typeerror:unhashable type: ' List '
3. Because the set itself is unordered, it is not duplicated. Therefore, you cannot read content by using an index or a slice. can only iterate through or use in,not in to access or judge a collection element
1 s10 = set ("aabbskll")2 for in S10: 3 print(i)
4. Collection Operation method
Add () adds characters as a whole
Update () adds a character as a single character
1S10 = Set ("Aabbskll")2S10.add ("aaaaaaa")#{' A ', ' s ', ' l ', ' k ', ' aaaaaaa ', ' B '}3 Print(S10)4S10.update ("GH")#{' aaaaaaa ', ' a ', ' s ', ' l ', ' B ', ' g ', ' h ', ' K '}5 Print(S10)6S10.remove ('a')#{' L ', ' s ', ' B ', ' G ', ' k ', ' h ', ' aaaaaaa '}7 Print(S10)
Python---collection learning