10day
Data type: Collection set
1, the definition of the collection
Collections: unordered, non-repeating combinations of data.
Feature: A, go to weight, put a list into a set, then automatically go heavy
b, the relationship test. Test the relationship between two sets of data, such as intersection, difference set, and set
2, the basic operation of the collection:
2.1 Create a collection:
s = {}
2.2 New
S.add () #若不重复则添加, if repeat is not added
S.update ([1,2,4]) #批量添加集合
S.copy () #复制一个集合
2.3 Delete
S.discard () #若有则删除元素, if no error
S.pop () #随机删除一个元素, if no error, return the deleted element
S.remove () #删除一个元素, if no error
S.clear () #清空
3, set of the relationship test
The relationship test of a set is divided into: intersection, difference set, set, symmetric difference set
3.1 Intersection: Two coincident parts of a set &
3.2 Difference set: In S1, not part of S2, there are two ways
The first type:-
S1-s2
Second type: S.difference ()
S1.difference (S2)
3.3 Set: There are S1 and S2 collections, there are two ways
First type: S.union ()
S1.union (S2)
The second type: | (Pipe character)
S1 | S2
3.4 Symmetric difference set: Only the set in S1 or S2 is present
S.symmetric_difference ()
4, the relationship between the set:
4.1 Subset: S.issubset () or S1>=S2
4.2 Superset: S.issperset () or S1<=S2
4.3 contains:
In,not in to determine whether an element is within a set
==,! = Determine if two sets are equal
4.4 Relationship:
There are generally three relationships between two sets: Intersect, disjoint, inclusive
The python species are judged by the following methods:
4.4.1 Disjoint: S.isdisjoint ()
Hexadecimal
1, 16 binary conversion
Binary: In the bin ()
Octal: 01234567 Oct ()
Hex: 0123456789ABCDEF Hex ()
---restore content ends---
Python Beginners Day Collection, Hex