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
add
#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
clear
#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
copy
#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
difference
    def difference_update(self, *args, **kwargs): # real signature unknown
        """ Remove all elements of another set from this set. """
        pass
difference_update
    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
symmetric_difference
    def symmetric_difference_update(self, *args, **kwargs): # real signature unknown
        """ Update a set with the symmetric difference of itself and another. """
        pass
symmetric_difference_update
#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
intersection
    def intersection_update(self, *args, **kwargs): # real signature unknown
        """ Update a set with the intersection of itself and another. """
        pass
intersection_update
#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
union

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

#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'} # 是分开增加的,不是作为一个整体增加
#那如何作为一个整体增加呢
posted @ 2017-05-10 14:39  lazyball  阅读(508)  评论(0编辑  收藏  举报