>>> 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']
>>>

最新文章

  1. Linux根文件系统分析之init和busybox
  2. (转)教你记住ASP.NET WebForm页面的生命周期
  3. SQL Server中的RAND函数的介绍和区间随机数值函数的实现
  4. global &amp; nonlocal
  5. Rating
  6. 解决JDeveloper运行慢的设置/BPM/SOA Server JVM参数设定
  7. Android开发之ContentProvider(内容提供者)
  8. C#实现发送邮件
  9. Android Broadcaset 简介
  10. 【转】基于RSA算法实现软件注册码原理初讨
  11. 工作中git 操作汇总
  12. BGP:我们不生产路由,而是路由的搬运工
  13. package,继承,访问修饰符
  14. echarts 折线图点击高亮
  15. DBC格式解析(数据部分)
  16. jQueryEasyUI学习笔记
  17. [转]Spark 踩坑记:数据库(Hbase+Mysql)
  18. php面向对象精要(1)
  19. C#编程(十九)----------部分类
  20. js屏蔽f12键

热门文章

  1. @Transactional之Spring事务深入理解
  2. 帝都Day6——图论
  3. Python中list作为默认参数的陷阱
  4. Sqoop环境安装
  5. 如何让nginx支持ThinkPHP框架(重点参考)
  6. Toad for Oracle针对于Oracle数据库的可视化管理工具使用
  7. table-列组
  8. git版本分支和分支、分支和主分支切换
  9. WPF样式学习三
  10. 【MFC】将当前的日期转化为1970年开始的秒计数