set() set
Set creation method:
1 #集合是无序的不重复的2 li = [11,22,11,33]3 a = set(li)4 print(a)5 {33,22,11}
a = {11,22,33,44= {22,5577= {11,22,33,44= {22,55c =(a) #discard移除集合不存在的元素不会报错,remove移除会报错 a.discard(99)
#intersection()取交集,intersection_update()同上
Implementation class of Set interface
To use Set Collections usually need to be declared as Set type and then instantiated through the implementation class of the Set interface. Commonly used implementation classes of the Set interface include the HashSet and TreeSet classes. The syntax format is as follows:
Set
Set
Since the objects in the Set collection are unordered, the results of traversing the Set collection are not the same as the order in which they were inserted into the Set collection.
The above is the detailed content of Introduction to the use of set() class. For more information, please follow other related articles on the PHP Chinese website!