>>> help(set)
Help on class set in module __builtin__: class set(object)
| set(iterable) --> set object
|
| Build an unordered collection of unique elements.#无序、独一无二的元素
|
| Methods defined here:
|
| __and__(...)
| x.__and__(y) <==> x&y
|
| __cmp__(...)
| x.__cmp__(y) <==> cmp(x,y)
|
| __contains__(...)
| x.__contains__(y) <==> y in x.
|
| __eq__(...)
| x.__eq__(y) <==> x==y
|
| __ge__(...)
| x.__ge__(y) <==> x>=y
|
| __getattribute__(...)
| x.__getattribute__('name') <==> x.name
|
| __gt__(...)
| x.__gt__(y) <==> x>y
|
| __iand__(...)
| x.__iand__(y) <==> x&y
|
| __init__(...)
| x.__init__(...) initializes x; see x.__class__.__doc__ for signature
|
| __ior__(...)
| x.__ior__(y) <==> x|y
|
| __isub__(...)
| x.__isub__(y) <==> x-y
|
| __iter__(...)
| x.__iter__() <==> iter(x)
|
| __ixor__(...)
| x.__ixor__(y) <==> x^y
|
| __le__(...)
| x.__le__(y) <==> x<=y
|
| __len__(...)
| x.__len__() <==> len(x)
|
| __lt__(...)
| x.__lt__(y) <==> x<y
|
| __ne__(...)
| x.__ne__(y) <==> x!=y
|
| __or__(...)
| x.__or__(y) <==> x|y
|
| __rand__(...)
| x.__rand__(y) <==> y&x
|
| __reduce__(...)
| Return state information for pickling.
|
| __repr__(...)
| x.__repr__() <==> repr(x)
|
| __ror__(...)
| x.__ror__(y) <==> y|x
|
| __rsub__(...)
| x.__rsub__(y) <==> y-x
|
| __rxor__(...)
| x.__rxor__(y) <==> y^x
|
| __sizeof__(...)
| S.__sizeof__() -> size of S in memory, in bytes
|
| __sub__(...)
| x.__sub__(y) <==> x-y
|
| __xor__(...)
| x.__xor__(y) <==> x^y
|
| add(...)
| Add an element to a set.
|
| This has no effect if the element is already present.
|
| clear(...)
| Remove all elements from this set.
|
| copy(...)
| Return a shallow copy of a set.
|
| difference(...)
| 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.)
|
| difference_update(...)
| Remove all elements of another set from this set.
|
| discard(...)
| Remove an element from a set if it is a member.
|
| If the element is not a member, do nothing.
|
| intersection(...)
| Return the intersection of two sets as a new set.
|
| (i.e. all elements that are in both sets.)
|
| intersection_update(...)
| Update a set with the intersection of itself and another.
|
| isdisjoint(...)
| Return True if two sets have a null intersection.
|
| issubset(...)
| Report whether another set contains this set.
|
| issuperset(...)
| Report whether this set contains another set.
|
| pop(...)
| Remove and return an arbitrary set element.
| Raises KeyError if the set is empty.
|
| remove(...)
| Remove an element from a set; it must be a member.
|
| If the element is not a member, raise a KeyError.
|
| symmetric_difference(...)
| Return the symmetric difference of two sets as a new set.
|
| (i.e. all elements that are in exactly one of the sets.)
|
| symmetric_difference_update(...)
| Update a set with the symmetric difference of itself and another.
|
| union(...)
| Return the union of sets as a new set.
|
| (i.e. all elements that are in either set.)
|
| update(...)
| Update a set with the union of itself and others.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __hash__ = None
|
| __new__ = <built-in method __new__ of type object at 0x1E1CD668>
| T.__new__(S, ...) -> a new object with type S, a subtype of T
通过下面例子,可以看出:集合是非重复的,集合是无序的。
 >>> d=set('chooses')
>>> d
set(['h', 'c', 'e', 's', 'o'])
>>> d
set(['h', 'c', 'e', 's', 'o'])
>>> d
set(['h', 'c', 'e', 's', 'o'])
>>>

如果需要有序的集合,可以改为list:

 >>> d=set('chooses')
>>> d
set(['h', 'c', 'e', 's', 'o'])
>>> d
set(['h', 'c', 'e', 's', 'o'])
>>> d
set(['h', 'c', 'e', 's', 'o'])
>>> mylist=list(d)
>>> mylist
['h', 'c', 'e', 's', 'o']
>>> mylist.sort()
>>> mylist
['c', 'e', 'h', 'o', 's']
>>>

Python中的集合set的更多相关文章

  1. python 中的集合set

    python中,集合(set)是一个无序排列,可哈希, 支持集合关系测试,不支持索引和切片操作,没有特定语法格式, 只能通过工厂函数创建.集合里不会出现两个相同的元素, 所以集合常用来对字符串或元组或 ...

  2. Python中的集合类型分类和集合类型操作符解析

    集合类型    数学上,把set称作由不同的元素组成的集合,集合(set)的成员通常被称作集合元素(set elements).    Python把这个概念引入到它的集合类型对象里.集合对象是一组无 ...

  3. python学习之【第七篇】:Python中的集合及其所具有的方法

    1.前言 python中的集合set与列表类似,它们最大的区别是集合内不允许出现重复元素,如果在定义时包含重复元素,会自动去重. 集合是无序的,集合中的元素必须是不可变类型.集合可以作为字典的key. ...

  4. 14.python中的集合

    什么是集合?正如其字面的意思,一堆东西集中合并到一起.乍一听貌似和容器没什么差别,嗯,好吧,集合也算是一种容器. 在学习这个容器有什么不同之前,先看看集合是如何创建的: a = set() #可变集合 ...

  5. python中的集合

    在python中,普通集合是可变数据类型 通过以下案例说明: >>> s = {1, 2, 3, 4} >>> id(s) 2108634636808 >&g ...

  6. 8、python中的集合

    集合是python中无序.可变的数据结构.集合与字典类似,集合中的元素必须是可哈希的(等同于字典中的键),也就是说集合中的元素是唯一.不可变的数据类型.这里前面说集合可变,后面又说集合中的元素不可变是 ...

  7. python中的集合、元组和布尔

    #元组,元组跟列表一样,只不过列表可读可写,而元组一般用来只读,不修改#python中不允许修改元组的数据,也包括不能删除其中的元素. t1 = ('a','b','c','d','s','a') & ...

  8. Python 中的集合 --set

    前言 在Python中,我们用[]来表示列表list,用()来表示元组tuple,那{}呢?{}不光可用来定义字典dict,还可以用来表示集合set. 集合 set 集合(set)是一个无序的不重复元 ...

  9. python 中的集合(set) 详解

    在Python set是基本数据类型的一种集合类型,它有可变集合(set())和不可变集合(frozenset)两种. 创建集合set.集合set添加.集合删除.交集.并集.差集的操作都是非常实用的方 ...

  10. python中set集合

    一.set集合的特性 访问速度快 天生解决重复问题 二.set变量申明 s1 = set() s2 = set([1,2,3]) 备注:第二种方式在set类中直接传入一个序列. 三.set类中方法大全 ...

随机推荐

  1. k8s缩放应用程序

    参考:https://kubernetes.io/docs/tutorials/kubernetes-basics/ 步骤1:扩展部署 要列出部署,请使用GET部署命令:kubectl get dep ...

  2. Node.js实现TCP和HTTP并作简单的比较

    TCP和Node 传输控制协议是一个面向连接的协议,换句话说,它是一个传输层的协议,它主要的职务呢,就是确保信息传输的正确性. 我们使用的很多如HTTP协议都是基于TCP的,为什么呢?因为我们不希望传 ...

  3. linux中的三种时间

    mtime [修改时间] 文件/目录的修改时间 ctime  [属性修改时间] 文件目录的属性的修改时间 atime  [访问时间]文件/目录的访问时间 stat 123.txt   File: `1 ...

  4. 深刻理解Linux进程间通信(IPC)

    https://www.ibm.com/developerworks/cn/linux/l-ipc/ linux下进程间通信的几种主要手段简介: 管道(Pipe)及有名管道(named pipe):管 ...

  5. JavaScript函数体系

    第4章  JavaScript函数 1. 函数基本介绍 ① 为什么需要函数 函数最大的好处就是将零散的代码封装到了一起,当我们要再次使用该功能的时候,不需要再重新书写代码,只需要调用封装好的函数就可以 ...

  6. window.open 打开Excel或者Word 无权限问题

    场景:后端C# ashx 前端:js js在对ashx返回结果进行window.open(url)  url为后端保存excel的一个地址 提示:无操作权限 url:为后端处理后,服务器上一个完整的路 ...

  7. 一起来学Spring Cloud | 第一章 :如何搭建一个多模块的springcloud项目

    在spring cloud系列章节中,本来已经写了几个章节了,但是自己看起来有些东西写得比较杂,所以重构了一下springcloud的章节内容,新写了本章节,先教大家在工作中如何搭建一个多模块的spr ...

  8. Router模块

    一.应用场景 监听浏览器地址栏URL的hash值(#后面的部分)的变化,用正则匹配出参数执行相应的JS方法.URL地址的hash部分充当业务逻辑的分发单位. 示例: <!DOCTYPE html ...

  9. substring、slice、substr的区别

    首先定义一个变量便于下面测试:var str = "xx351223441";   substring: str.substring(form,to):从字符串里截取下标为form ...

  10. EasyUI Combobox 的 onChange,onSelect,onClick 事件

    EasyUI 中 Combobox 选项发生改变时会触发 onChange,onSelect,onClick,3 个事件.最近要做一个级联的 Combo 菜单,类似于选择地址时让用户填写省,市,区的菜 ...