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 & ...
随机推荐
- SpringBoot | 问题 | 注解方式下无法发现Bean
在排除注解的问题后,考虑扫描类的位置, [SpringBoot项目的Bean装配默认规则是根据Application类所在的包位置从上往下扫描! “Application类”是指SpringBoot项 ...
- Udp实现省略编码
class My_Socket(socket.socket): def __init__(self, encoding='utf-8'): self.encoding = encoding super ...
- UWP 动画
一:StoryBoard 一般翻译成演示图版或者故事板,就像电影中的情节串联板,它是一个动画时间线的容器. 二:动画的分类 简单动画:以Animation结尾,例如DoubleAnimat ...
- 18.3.2从Class上获取信息(内部类接口等)
内部类 接口.枚举.注释类型
- [未读]JavaScript高效图形编程
去年买来就一直搁置,因为是js游戏相关,暂时还用不到.
- SqlSessionFactory
源码: public interface SqlSessionFactory { SqlSession openSession(); SqlSession openSession(boolean va ...
- check_http.c:312: error: ‘ssl_version’
安装nagios-plugins-1.4.16,安装的过程中出现了错误,提示如下.check_http.c:312: error: ‘ssl_version’ undeclared (first us ...
- General mistakes in parallel computing
这是2013年写的一篇旧文,放在gegahost.net上面 http://raison.gegahost.net/?p=97 March 11, 2013 General mistakes in ...
- 三星系列NXP系列核心板设计研发-迅为嵌入式ARM方案提供商
多种核心板平台,从硬件原型设计.layout.硬件驱动,操作系统移植.中间到上层应用等方面. 三星系列核心板: 1. SCP-4412核心板 三星Exynos4412 四核 Cortex-A9 主频为 ...
- 应用程序员眼中的数据库管理系统:API+数据库语言
应用程序员眼中的数据库管理系统:API+数据库语言 sqlite3_open_v2 https://www.cnblogs.com/cchust/p/5121559.html