Python data type-Set (set)

Set is a disorder not repeat sequence
may be used braces {}, or the set () function to create
Note: Create an empty set must be set () instead of {}, {} because the dictionary is used to create an empty
Create Format:
{value1, value2, value3, value4...}
or
set(value)
sets can be- (difference set) & (intersection) | (union) ^ (inverse intersection)

Set (collection) running code is as follows:

s=set([1,2,3]) 
print(s)
s=set([1,1,2,2,2,3,3]) #自动去重
print(s)
s1=set([1,2,3])
s2=set([2,3,4])
print(s1&s2) # 求交集
print(s1|s2)  # 求并集

The code shows the result:

{
    
    1, 2, 3}
{
    
    1, 2, 3}
{
    
    2, 3}
{
    
    1, 2, 3, 4}

Guess you like

Origin blog.csdn.net/weixin_42961082/article/details/111504048