set-集合功能介绍
叨逼叨:
#集合 不可重复的列表 可变类型
#1.添加 无则添加有则不操作 不可重复
# se = {'alex','eric','seven'} # se.add('qiqi') # se.add('blex') # print(se)
def add(self, *args, **kwargs): # real signature unknown """ Add an element to a set. This has no effect if the element is already present. """ pass
#2.清空
# se = {'alex','eric','seven'} # se.clear() # print(se) #执行结果: #set()
def clear(self, *args, **kwargs): # real signature unknown """ Remove all elements from this set. """ pass
#3.拷贝 浅拷贝
# se = {'alex','eric','qiqi'} # v = se.copy() # print(v)
def copy(self, *args, **kwargs): # real signature unknown """ Return a shallow copy of a set. """ pass
#4. 找不同
#1> difference 输出 se1中有的,se2中无的 赋值给新的变量 # se1 = {'alex','eric','qiqi','dh'} # se2 = {'alex','eric','gege','yiyi'} # v = se1.difference(se2) # print(v) #2> difference_update 输出 将se1中有的,se2中无的 重新赋值给se1 (se1会被清空,变成se1中有的,se2中无的值) # se1 = {'alex','eric','qiqi','dh'} # se2 = {'alex','eric','gege','yiyi'} # se1.difference_update(se2) # print(se1) #3> symmetric_difference 将两者不同的 赋值给新的变量 # se1 = {'alex','eric','qiqi','dh'} # se2 = {'alex','eric','gege','yiyi'} # v = se1.symmetric_difference(se2) # se1.symmetric_difference_update(se2)#将两者不同的 覆盖赋值给se1 # print(se1) # print(v)
def difference(self, *args, **kwargs): # real signature unknown """ Return the difference of two or more sets as a new set. (i.e. all elements that are in this set but not the others.) """ pass
def difference_update(self, *args, **kwargs): # real signature unknown """ Remove all elements of another set from this set. """ pass
def symmetric_difference(self, *args, **kwargs): # real signature unknown """ Return the symmetric difference of two sets as a new set. (i.e. all elements that are in exactly one of the sets.) """ pass
def symmetric_difference_update(self, *args, **kwargs): # real signature unknown """ Update a set with the symmetric difference of itself and another. """ pass
#5.交集
# se1 = {'alex','eric','qiqi','dh'} # se2 = {'alex','eric','gege','yiyi'} # v = se1.intersection(se2) # se1.intersection_update(se2) #将交集覆盖赋值给se1 # print(se1) # print(v)
def intersection(self, *args, **kwargs): # real signature unknown """ Return the intersection of two sets as a new set. (i.e. all elements that are in both sets.) """ pass
def intersection_update(self, *args, **kwargs): # real signature unknown """ Update a set with the intersection of itself and another. """ pass
#6.并集
# se1 = {'alex','eric','qiqi','dh'} # se2 = {'alex','eric','gege','yiyi'} # v = se1.union(se2) # print(v)
def union(self, *args, **kwargs): # real signature unknown """ Return the union of sets as a new set. (i.e. all elements that are in either set.) """ pass
#7.移除
##discard # se1 = {'alex','eric','qiqi','dh'} # se1.discard('qiqi') # print(se1) ##remove # se1 = {'alex','eric','qiqi','dh'} # se1.remove('alex') # print(se1) ##pop #不会用呢
举例里有疑问
def discard(self, *args, **kwargs): # real signature unknown """ Remove an element from a set if it is a member. If the element is not a member, do nothing. """ pass
def remove(self, *args, **kwargs): # real signature unknown """ Remove an element from a set; it must be a member. If the element is not a member, raise a KeyError. """ pass
def pop(self, *args, **kwargs): # real signature unknown """ Remove and return an arbitrary set element. Raises KeyError if the set is empty. """ pass
#8. for循环
# s1 = {"alex",'eric','tony','李泉','李泉11'} # for i in s1: # print(i) # s1 = {"alex",'eric','tony','李泉','李泉11',(11,22,33)} # for i in s1: # print(i)
#9.增加
#解决了疑问再添加
#还剩的功能
# isdisjoint
# issubset
# issuperset
##疑问
pop 貌似和别的不一样呢 不会用了
# se1 = {'alex','eric','qiqi','dh'}
# print(se1)
#打印结果
#{'qiqi', 'eric', 'dh', 'alex'} 和原来的顺序不一样呢 随机的????
# se1 = {'alex','eric','qiqi','dh'}
# se1.update('f')
# print(se1)
#打印结果
#{'f', 'qiqi', 'dh', 'eric', 'alex'} #这个位置也是随机插入吗???
# se1 = {'alex','eric','qiqi','dh'}
# se1.update('abcdef')
# print(se1)
#打印结果
#{'qiqi', 'b', 'e', 'f', 'a', 'eric', 'dh', 'c', 'd', 'alex'} # 是分开增加的,不是作为一个整体增加
#那如何作为一个整体增加呢