python 基础 set 集合类型补充
为啥今天又重提这个数据类型呢?平时用的少,等要用起来的时候才发现,自己对这块啥都不知道了,so,今天就把这块再梳理一下咯。
一、set集合,是一个无序且不重复的元素集合。这一点是非常重要的。
二、集合中的方法介绍:
class set(object):
"""
set() -> new empty set object
set(iterable) -> new set object Build an unordered collection of unique elements.
"""
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 def clear(self, *args, **kwargs): # real signature unknown
""" Remove all elements from this set. 清除内容"""
pass 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. A中存在,B中不存在 (i.e. all elements that are in this set but not the others.)
"""
pass def difference_update(self, *args, **kwargs): # real signature unknown
""" Remove all elements of another set from this set. 从当前集合中删除和B中相同的元素"""
pass 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 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 def intersection_update(self, *args, **kwargs): # real signature unknown
""" Update a set with the intersection of itself and another. 取交集并更更新到A中 """
pass def isdisjoint(self, *args, **kwargs): # real signature unknown
""" Return True if two sets have a null intersection. 如果没有交集,返回True,否则返回False"""
pass def issubset(self, *args, **kwargs): # real signature unknown
""" Report whether another set contains this set. 是否是子序列"""
pass def issuperset(self, *args, **kwargs): # real signature unknown
""" Report whether this set contains another set. 是否是父序列"""
pass def pop(self, *args, **kwargs): # real signature unknown
"""
Remove and return an arbitrary set element.
Raises KeyError if the set is empty. 移除元素
"""
pass 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 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 def symmetric_difference_update(self, *args, **kwargs): # real signature unknown
""" Update a set with the symmetric difference of itself and another. 对称差集,并更新到a中 """
pass 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 def update(self, *args, **kwargs): # real signature unknown
""" Update a set with the union of itself and others. 更新 """
pass
集合方法摘录
三、常用方法举例:
linux = set(['alex','jack','rain','sb'])
python = set(['sb','alex','mack','rachel']) #集合linux与集合python 中都有的(交集)
a = linux.intersection(python)
print(a) # {'sb', 'alex'} # 求差集 linux 中有而python中没有的
b = linux.difference(python)
print(b) # {'rain', 'jack'}
集合部分的简单操作也就这些内容了。
python 基础 set 集合类型补充的更多相关文章
- Python中的集合类型分类和集合类型操作符解析
集合类型 数学上,把set称作由不同的元素组成的集合,集合(set)的成员通常被称作集合元素(set elements). Python把这个概念引入到它的集合类型对象里.集合对象是一组无 ...
- python基础数据类型--集合(set)
python基础数据类型--集合(set) 集合是一个数学概念由一个或多个确定的元素所构成的整体叫做集合 集合中的三个特征 1.确定性(元素必须死可hash) 2.互异性(去重) 3.无序性(集合中的 ...
- python基础之序列类型的方法——字符串方法
python基础之序列类型的方法--字符串方法 Hello大家好,我是python学习者小杨同学,经过一段时间的沉淀(其实是偷懒不想更新),我终于想起了自己的博客账号,所以这次带来的是序列方法的后半部 ...
- python基础之数值类型与序列类型
Hello大家好,我是python学习者小杨同学,已经学习python有一段时间,今天将之前学习过的内容整理一番,在这与大家分享与交流,现在开始我们的python基础知识之旅吧. 数值类型与序列类型 ...
- python set type 集合类型的数据介绍 (set frozenset)
python支持数学中的集合概念,如:通过in,not in 可以检查某元素是否在,不在集合中. python有两种集合类型,set(可以变的,不能哈希,不能用作字典的key),frozenset ...
- Python基础操作-集合
在Python set是基本数据类型的一种集合类型,它有可变集合(set())和不可变集合(frozenset)两种.创建集合set.集合set添加.集合删除.交集.并集.差集的操作都是非常实用的方法 ...
- Python笔记_第一篇_面向过程_第一部分_5.Python数据类型之集合类型(set)
集合!Python中的集合数据基本上是为了方便数学计算使用的. 什么是集合? 集合就是“确定的一堆东西”.集合里面的东西叫做元素. 特点:1. 集合里面是没有重复的元素的. 2. ...
- Python学习笔记——集合类型
集合类型有两种不同的类型——可变集合(set)和不可变集合(frozenset) 可变集合不是可哈希的,不能用作字典的键,也不能用做其他集合中的元素 不可变集合是有哈希值的,能被用做字典的键或者是作为 ...
- python基础之集合,字符编码
六.集合类型 1.用途:关系运算 2.定义方式:s = {1,2,’a’} {}内用,分隔开多个元素,每个元素都必须是不可变(即可hash)类型 强调:2.1集合内的元素时无序的 2.2集合内的元素不 ...
随机推荐
- ES6学习总结一(变量;箭头函数;解构赋值)
一.变量 var 1 可以重复声明(var a=1;var a=7;)(一开始用着会觉得限制很少,但是在大型项目会麻烦,人多嘴杂的时候定义重复了就容易出问题还不好找) 2 无法限制修改 3 没有块级 ...
- PLSQL Developer连接远程数据库的配置
去Oracle的安装目录找到:D:\oracle\NETWORK\ADMIN这个路径下面的tnsnames.ora文件 修改文件: 这个是本地的 ORCL = (DESCRIPTION = (ADDR ...
- Spark2.1.0官方文档
Spark 概述 Apache Spark是一个快速和通用的集群计算系统.它提供Java,scala,Python.R语言的APIs,以及支持一般执行图形的优化引擎. 它还支持一组丰富的高级工具,包括 ...
- WBS
Need 需求分析: 为了满足中老年人因工作忙碌而无暇阅读的痛苦,我们设计推广出一款听书软件.可以给中老年人带来的好处是不再受繁琐的听书软件的束缚,操作简单,携带便捷. Approach 实现方法: ...
- phpStorm安装方法
1)下载 http://big2.h5gamen.com/soft/jetbrainscrack-2.6.2.zip 放到phpstorm安装目录下的lib文件夹 如放到f盘 F:\PhpStorm ...
- protobuf(quickStart)
1.简介 Protocol Buffers是Google开发一种数据描述语言,能够将数据进行序列化,可用于数据存储.通信协议等方面. 可以理解成更快.更简单.更小的JSON或者XML,区别在于Prot ...
- ELK学习笔记(五)简单搜索和DSL查询
检索文档 现在我们有一些数据存储在Elasticsearch中,我们可以开始处理这个应用程序的业务需求. 这在Elasticsearch中很容易.我们只需执行HTTP GET请求并指定文档的地址--索 ...
- Bower快速学习
什么是bower? Bower是一个前端类库管理器,它可用于搜索.安装和卸载如JavaScript.HTML.CSS之类的类库. 官网:https://bower.io/ 安装bower 使用npm, ...
- sharepoint REST API 获取文件夹及文件
使用REST操作文件夹: 获取文件夹 url: http://site url/_api/web/GetFolderByServerRelativeUrl('/Shared Documents')/f ...
- zabbix自定义key监控memcache状态及其他服务进程
一.在客户端 1.到/usr/loca/zabbix/conf/zabbix_agentd.conf里添加 UserParameter=memcached_stats[*],(echo ...