In Python, set represents the collection, list stands for lists, dict represents the dictionary
The difference between set and Dict is that the dict is a storage key-value, each key is unique, the set is stored as a key relative to the dict, and the key is unique, and the list can be stored in addition to the variables.
Dict={"A": 1, "B": 2, "C": 3}
Set={"A", "B", "C"}
List=["A", "B," C "]
1.set usage
There are two common methods for adding Python collections, namely add and update.
Add method: The element to be passed into the collection as an entire, for example:
>>> a = set (' Boy ')
>>> a.add (' python ')
>>> A
Set ([' Y ', ' python ', ' B ', ' O '])
The Update method: Splits the element to be passed in as an individual into the collection, for example:
>>> a = set (' Boy ')
>>> a.update (' python ')
>>> A
Set ([' B ', ' H ', ' o ', ' n ', ' P ', ' t ', ' Y '])
Collection Delete Action method: remove
Set ([' Y ', ' python ', ' B ', ' O '])
>>> a.remove (' python ')
>>> A
Set ([' Y ', ' b ', ' O '])
Advanced usage of Set, set operation
2.list usage
Add append (e) to the list, append to the bottom
Remove Pop (index i) from the list to delete the element that contains the index
Removing the Remove (e) method from the list, deleting the element E
High-level usage of the list list.extend (LIST2) or a set of two lists added together with +
Difference: Extend () is the element that adds list2 to the list and does not create a new element
+ is to generate a new list
3.dict Dictionary Usage
add element dict[']= '
Delete Element pop
4.list and set convert each other
The differences and usage of collection set, Dictionary dict and list lists in Python