zoukankan      html  css  js  c++  java
  • python基础之set集合

    set集合
    # 1.set 无序,不重复
    # 创建集合的三种方式:
    # s1 = {11,22}
    # s2 = set() #空集合
    # or
    # s3 = set([11,22,33,4])
    # print(type(set))
    # 2.操作集合
    # s = set()
    # print(s)
    # s.add(123)
    # print(s)
    # s.clear()#清除所有的内容
    # print(s)
    # s.copy()#浅拷贝
    # print(s)
    # s1 = {11,22,33}
    # s2 = {22,33,44,55}
    #差集,从一个集合减去另一个集合
    #s3 = s1.difference(s2)
    # s3 = s2.difference(s1)
    # s3 = s1.symmetric_difference(s2)#对称差集,不同的取出
    # print(s3)
    # s1.difference_update(s2)#不同更新进s1
    # print(s1)
    
    #
    # s1 = {11,22,33,44,55}
    # s1.discard(11)#指定移除,不存在不报错
    # s1.remove(22)#指定移除,不存在报错
    # ret = s1.pop()#随机移除,这样知道随机移除的哪一个
    # print(s1)
    # print(ret)
    
    # s1 = {11,22,33}
    # s2 = {22,33,44,55}
    # # print(s1.intersection(s2))#取交集
    # # s1.intersection_update(s2)#取出交集并更新给s1
    # # print(s1)
    # # print(s1.union(s2))#取交集
    # li = [11,22,33,44,55,66]
    # s1.update(li)#批量添加,更新,可以被for循环的对象
    # print(s1)
    
    class set(object):
        """
        set() -> new empty set object
        set(iterable)(元组) -> new set object
        
        Build an unordered collection of unique elements.
        """
        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#添加
    
        def clear(self, *args, **kwargs): # real signature unknown
            """ Remove all elements from this set. """
            pass#清空
    
        def copy(self, *args, **kwargs): # real signature unknown
            """ Return a shallow copy of a set. """
            pass#复制
    
        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 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 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
    
        def isdisjoint(self, *args, **kwargs): # real signature unknown
            """ 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
    
        def update(self, *args, **kwargs): # real signature unknown
            """ Update a set with the union of itself and others. """
            pass#更新,把一个集合有的更新到另一个集合没有的
  • 相关阅读:
    Linux安装nginx
    Linux安装vsftp服务
    maven的Tomcat插件使用
    Mybatis逆向工程生成代码
    千里之行,始于足下
    java 通过反射获取注解
    天气预报需要用到的jar包
    JDBC 利用反射 配置文件
    从网页下载图片的代码
    装箱/拆箱 对象排序
  • 原文地址:https://www.cnblogs.com/qwerdf/p/6565256.html
Copyright © 2011-2022 走看看