python set 集合

python的set, 是一個無序不重複元素集python

a = {'a','b','c'}
b = ('b','e','f')

a.add('zjk') 是把要傳入的元素作爲一個整個添加到集合中ide

{'c', 'b', 'a', 'zjk'}this

a.update('zjk')是把要傳入的元素拆分,作爲個體傳入到集合中對象

{'j', 'b', 'k', 'a', 'z', 'c'}element

a.remove 集合刪除rem

a.remove('zjk')    #元素不存在會報錯
it

a.clear  刪除全部io

a.clear()class

a.discard('sss')  # 元素不存在,什麼都不作date

print(a.intersection(b))   返回交集

a.intersection_update(b)
print(a)         # 取交集,修改原來set

{b}            


print(a.difference(b))  #以a爲參考對比不一樣

a.difference_update(b)  #刪除 a和b 相同的

{'zjk', 'c', 'a'}

def isdisjoint(self, *args, **kwargs): # real signature unknown
        """ 若是沒有交集,返回true  """
        """ Return True if two sets have a null intersection. """
        pass

    def issubset(self, *args, **kwargs): # real signature unknown
        """ 是不是子集 """
        """ Report whether another set contains this set. """
        pass

    def issuperset(self, *args, **kwargs): # real signature unknown
        """ 是不是父集 """
        """ Report whether this set contains another set. """
        pass

    def pop(self, *args, **kwargs): # real signature unknown
        """ 移除 """
        """
        Remove and return an arbitrary set element.
        Raises KeyError if the set is empty.        """
        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 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

    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
相關文章
相關標籤/搜索