set()集合基本操作
运用频次:☆☆
set是一个无序且不重复元素集,基本操作如下:
1. 创建set集合,会自动转换成set类型

2. add():添加元素
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

3. clear():清除元素
def clear(self, *args, **kwargs): # real signature unknown
#清除元素
""" Remove all elements from this set. """
pass

3. copy():浅拷贝
def copy(self, *args, **kwargs): # real signature unknown
""" Return a shallow copy of a set. """
pass
4. difference():取差集,不更新原集合
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

5. difference_update():取差集,更新原集合
def difference_update(self, *args, **kwargs): # real signature unknown
# 取差集,更新原集合,不生成新的集合
""" Remove all elements of another set from this set. """
pass

6. discard():删除元素,更新原集合
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

7. intersection():取交集,返回一个新的集合
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

8. intersection_update():取交集,更新原集合
def intersection_update(self, *args, **kwargs): # real signature unknown
# 取交集,更新原集合
""" Update a set with the intersection of itself and another. """
pass

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

10. issubset():判断是否是子集,是则返回True
def issubset(self, *args, **kwargs): # real signature unknown
# 判断另一集合是否包含该集合,是则返回True
""" Report whether another set contains this set. """
pass

11. issuperset():判断是否是父集,是则返回True
def issuperset(self, *args, **kwargs): # real signature unknown
# 判断该集合是否包含另一集合,是则返回True
""" Report whether this set contains another set. """
pass

12. pop():随机删除一个元素并返回,更新原集合
def pop(self, *args, **kwargs): # real signature unknown
# 随机删除一个元素并返回,更新原集合
"""
Remove and return an arbitrary set element.
Raises KeyError if the set is empty.
"""
pass

13. remove():删除元素,更新原集合
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

14. symmetric_difference():取差集,不更新原集合
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

15. symmetric_difference_update():取差集,更新原集合
def symmetric_difference_update(self, *args, **kwargs): # real signature unknown
# 取差集,更新原集合
""" Update a set with the symmetric difference of itself and another. """
pass

16. union():取并集,不更新原集合
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

17. update():取并集,更新原集合
def update(self, *args, **kwargs): # real signature unknown
# 取并集,更新原集合
""" Update a set with the union of itself and others. """
pass

set()集合基本操作的更多相关文章
- 集合基本操作 Python DAY2
集合本身具有两个特性 1.去重 2.关系测试 列表转集合的两种写法: list_1=[1,2,3,4,1,2,7,8,] list_1=set(list_1) #方法二 list_2=set([1, ...
- JavaScript 集合基本操作
参考 MDN 集合 Array 1. 2种创建数组的方式 var fruits = [] ; var friuits = new Array(); 2. 遍历 fruits.forEach(funct ...
- Java 中的集合接口——List、Set、Map
Java 中的集合接口——List.Set.Map 什么叫集合:集合就是Java API所提供的一系列类的实例,可以用于动态存放多个对象.这跟我们学过的数组差不多,那为什么我们还要学集合,我们看看数组 ...
- python集合类型
集合类型简介 集合也是容器,其内元素都是无序.唯一.不可变的.它常用来做成员测试.移除重复数据.数据计算(比如交集.并集.差集). 集合Set是dict的无value版.集合也使用大括号包围: > ...
- python元组,集合类型,及字典补充
一.元组 元组与列表基本相同,不同之处在于元组只能存不能取,当多个值没有改的需求时,用元组更合适 元组的基本操作 1.创建元组: t = (1, 2, 3, 4, 2,4,) t = (1,) #单个 ...
- Scala集合类型详解
Scala集合 Scala提供了一套很好的集合实现,提供了一些集合类型的抽象. Scala 集合分为可变的和不可变的集合. 可变集合可以在适当的地方被更新或扩展.这意味着你可以修改,添加,移除一个集合 ...
- Python自动化开发 - 字符编码、文件和集合
本节内容 字符编码 文件操作 集合 一.字符编码 1.编码 计算机只能处理数字,如果要处理文本,就必须先把文本转换为数字才能处理.解决思路:数字与符号建立一对一映射,用不同数字表示不同符号. ASCI ...
- Spark记录-Scala集合
Scala列表 Scala列表与数组非常相似,列表的所有元素都具有相同的类型,但有两个重要的区别. 首先,列表是不可变的,列表的元素不能通过赋值来更改. 其次,列表表示一个链表,而数组是平的. 具有类 ...
- 【python】-- 深浅copy、集合
深浅copy 1.数字.字符串的copy: 赋值(=).浅拷贝(copy)和深拷贝(deepcopy)其实都一样,因为它们永远指向同一个内存地址: >>> import copy & ...
随机推荐
- Spring Cache无效的问题以及解决办法
http://blog.csdn.net/kimylrong/article/details/50126979 @Cacheable标注的方法,如果其所在的类实现了某一个接口,那么该方法也必须出现在接 ...
- JSP | 基础 | 两种方式循环输出
用循环连续输出三个你好,字体从小变大 第一种: <body> <%! //通过表达式方式调用实现 String HelloJSP1(){ String str = "&qu ...
- python之yaml模块和ddt模块
aml文件是专门用来写配置文件的语言,非常简洁和强大,远比json格式方便. 在PC中新建一个yml/yaml为为缩略名的文件,输入信息见下图 新建一个py文件处理yml文件,直接处理成字典格式 缩进 ...
- 网站如何从http升级成https
基本概念: HTTP: 是互联网上应用最为广泛的一种网络协议,是一个客户端和服务器端请求和应答的标准,用于从WWW服务器传输超文本到本地浏览器的传输协议,它可以使浏览器更加高效,使网络传输减少. HT ...
- 转-sql之left join、right join、inner join的区别
left join(左联接) 返回包括左表中的所有记录和右表中联结字段相等的记录 right join(右联接) 返回包括右表中的所有记录和左表中联结字段相等的记录inner join(等值连接) 只 ...
- AJPFX关于面向对象之封装,继承,多态 (下)
(3)private: 对于对于成员来说:只能在该成员隶属于的类中访问. 对于类来说:类不可以声明为private. 4)protected: 对于对于成员来说:相同包中的类可以访问(包访问权限):基 ...
- 洛谷 P2580 于是他错误的点名开始了
题目背景 XS中学化学竞赛组教练是一个酷爱炉石的人. 他会一边搓炉石一边点名以至于有一天他连续点到了某个同学两次,然后正好被路过的校长发现了然后就是一顿欧拉欧拉欧拉(详情请见已结束比赛CON900). ...
- liunx 修改IP地址
1.安装centos系统,这里就不详细说明了. 2.进入到 vi /etc/sysconfig/network-scripts/ifcfg-eth0 后面的名称有些可能不同 其中,有些可能没 ...
- vue点击时动态改变样式 ------- 最简单的方法
vue点击时动态改变样式 template中 <li :class="{ active:index==isActive }" @click="changeValue ...
- js 时间戳 随机数 new Date().getTime()
一:时间转时间戳:javascript获得时间戳的方法有四种,都是通过实例化时间对象 new Date() 来进一步获取当前的时间戳 1.var timestamp1 = Date.parse(new ...