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 & ...
随机推荐
- hud3371 Connect the Cities 简单最小生成树
//我看过Discuss说不能用克鲁斯卡尔因为有很多边 //但是只能用G++过,C++的确超时 #include <stdio.h> #include <string.h> # ...
- $.ajax从后台取数据 然后做字符串拼接的例子
- Lightoj 1044 - Palindrome Partitioning (DP)
题目链接: Lightoj 1044 - Palindrome Partitioning 题目描述: 给一个字符串,问至少分割多少次?分割出来的子串都是回文串. 解题思路: 先把给定串的所有子串是不 ...
- 解决 Cordova命令突然无法使用问题.
问题背景 之前一直在做 Cordova 方面, 然后准备自己尝试使用 Vue + WebPack 再配合 Cordova 做一个 App . 更新了 npm , 然后然后, 我的 cordova 这个 ...
- adb shell报错:error: insufficient permissions for device的解决办法
1.错误描述 执行 adb shell 时,报错如下; error: insufficient permissions for device 2.解决办法 1,终端执行 lsusb 结果如下,注意绿 ...
- vue项目node升级后,node-saas报错解决办法
ERROR in ./node_modules/_extract-text-webpack-plugin@3.0.2@extract-text-webpack-plugin/dist/loader.j ...
- AndroidStudio中使用SVN
AndroidStudio中使用SVN提交项目 1.安装SVN,我选择使用TortoiseSVN-1.8.7.25475-x64-svn-1.8.9.msi(安装文件地址如下:http://downl ...
- (转)Synopsys工具简介
DC Ultra--Design Compiler的最高版本 在Synopsys软件中完整的综合方案的核心是DC UltraTM,对所有设计而言它也是最好级别的综合平台.DC Ultra添加了全面的数 ...
- SQL函数 Nullif
函数 Nullif 功能: 如果两个函数都为空字符串则返回null 语法: Nullif(参数1,参数2) 一般该函数与函数coalesc一起使用 例: coalesce ( nullif ( [参数 ...
- MongoDB最简单的入门教程之五-通过Restful API访问MongoDB
通过前面四篇的学习,我们已经在本地安装了一个MongoDB数据库,并且通过一个简单的Spring boot应用的单元测试,插入了几条记录到MongoDB中,并通过MongoDB Compass查看到了 ...