一、集合的特点:
1、访问速度快
2、天生解决了重复问题
二、集合的定义方法:
a=set()
b=set(['a','b','c'])
三、集合中的方法:
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
eg:
![](https://images2015.cnblogs.com/blog/1075153/201612/1075153-20161210111733272-388808584.png)
![](https://images2015.cnblogs.com/blog/1075153/201612/1075153-20161210111743163-272559496.png)
def clear(self, *args, **kwargs): # real signature unknown
"""
Remove all elements from this set.
清空集合
"""
pass
eg:
![](https://images2015.cnblogs.com/blog/1075153/201612/1075153-20161210111950491-833656570.png)
![](https://images2015.cnblogs.com/blog/1075153/201612/1075153-20161210111959132-354734493.png)
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
eg:
![](https://images2015.cnblogs.com/blog/1075153/201612/1075153-20161210112722085-183204429.png)
![](https://images2015.cnblogs.com/blog/1075153/201612/1075153-20161210112733647-756885232.png)
def difference_update(self, *args, **kwargs): # real signature unknown
"""
Remove all elements of another set from this set.
求两个集合的不同(差集),改变原来的集合
"""
pass
eg:
![](https://images2015.cnblogs.com/blog/1075153/201612/1075153-20161210113212663-794246164.png)
![](https://images2015.cnblogs.com/blog/1075153/201612/1075153-20161210113222538-1940364757.png)
![](https://images2015.cnblogs.com/blog/1075153/201612/1075153-20161210113244960-497138297.png)
![](https://images2015.cnblogs.com/blog/1075153/201612/1075153-20161210113254897-1604712344.png)
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
![](https://images2015.cnblogs.com/blog/1075153/201612/1075153-20161210122705522-1595364401.png)
![](https://images2015.cnblogs.com/blog/1075153/201612/1075153-20161210122715116-432028773.png)
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
eg:
![](https://images2015.cnblogs.com/blog/1075153/201612/1075153-20161212144759792-403790311.png)
![](https://images2015.cnblogs.com/blog/1075153/201612/1075153-20161212144811839-1275849465.png)
def intersection_update(self, *args, **kwargs): # real signature unknown
"""
Update a set with the intersection of itself and another.
求两个集合的交集,并改变原集合
"""
pass
eg:
![](https://images2015.cnblogs.com/blog/1075153/201612/1075153-20161212144929761-1769801170.png)
![](https://images2015.cnblogs.com/blog/1075153/201612/1075153-20161212144939604-400487812.png)
def isdisjoint(self, *args, **kwargs): # real signature unknown
"""
Return True if two sets have a null intersection.
判断两个集合是否没有交集,如果是返回True,如果不是返回False
"""
pass
eg:
![](https://images2015.cnblogs.com/blog/1075153/201612/1075153-20161212145207729-306284019.png)
![](https://images2015.cnblogs.com/blog/1075153/201612/1075153-20161212145217433-842936397.png)
def issubset(self, *args, **kwargs): # real signature unknown
"""
Report whether another set contains this set.
判断一个集合是否是另一个集合的子集
"""
pass
eg:
![](https://images2015.cnblogs.com/blog/1075153/201612/1075153-20161212145524589-1055406301.png)
![](https://images2015.cnblogs.com/blog/1075153/201612/1075153-20161212145534823-733160473.png)
def issuperset(self, *args, **kwargs): # real signature unknown
"""
Report whether this set contains another set.
判断一个集合是否包含另一个集合
"""
pass
eg:
![](https://images2015.cnblogs.com/blog/1075153/201612/1075153-20161212145726167-1806486550.png)
![](https://images2015.cnblogs.com/blog/1075153/201612/1075153-20161212145734151-2141233627.png)
def pop(self, *args, **kwargs): # real signature unknown
"""
Remove and return an arbitrary set element.
Raises KeyError if the set is empty.
弹出集合中的元素
"""
pass
eg:
![](https://images2015.cnblogs.com/blog/1075153/201612/1075153-20161214093527917-690597036.png)
![](https://images2015.cnblogs.com/blog/1075153/201612/1075153-20161214093538886-388507110.png)
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
eg:
![](https://images2015.cnblogs.com/blog/1075153/201612/1075153-20161214093804917-501072286.png)
![](https://images2015.cnblogs.com/blog/1075153/201612/1075153-20161214093813636-1352461905.png)
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
eg:
![](https://images2015.cnblogs.com/blog/1075153/201612/1075153-20161214094919433-1136987229.png)
![](https://images2015.cnblogs.com/blog/1075153/201612/1075153-20161214094928183-942815929.png)
def symmetric_difference_update(self, *args, **kwargs): # real signature unknown
"""
Update a set with the symmetric difference of itself and another.
两个集合不相同的元素,并改变原集合
"""
pass
eg:
![](https://images2015.cnblogs.com/blog/1075153/201612/1075153-20161214100221573-549970989.png)
![](https://images2015.cnblogs.com/blog/1075153/201612/1075153-20161214100230511-1393455487.png)
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
eg:
![](https://images2015.cnblogs.com/blog/1075153/201612/1075153-20161214100910729-1006942870.png)
![](https://images2015.cnblogs.com/blog/1075153/201612/1075153-20161214100920464-1699568162.png)
def update(self, *args, **kwargs): # real signature unknown
"""
Update a set with the union of itself and others.
改变原集合
"""
pass
eg:
![](https://images2015.cnblogs.com/blog/1075153/201612/1075153-20161214101120323-24760669.png)
![](https://images2015.cnblogs.com/blog/1075153/201612/1075153-20161214101129433-1304721838.png)