014-python基础-set集合
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了014-python基础-set集合,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3315字,纯文字阅读大概需要5分钟。
内容图文
![014-python基础-set集合](/upload/InfoBanner/zyjiaocheng/1222/275d630596c54411b8da4be01678f598.jpg)
集合是一个无序的,不重复的数据组合,它的主要作用如下:
- 去重,把一个列表变成集合,就自动去重了
- 关系测试,测试两组数据之前的交集、差集、并集等关系
注:作为一个无序的集合,sets不记录元素位置或者插入点。因此sets不支持indexing,slicing(切片)
1 class set(object): 2 """ 3 set() -> new empty set object 4 set(iterable) -> new set object 5 6 Build an unordered collection of unique elements. 7 """ 8 def add(self, *args, **kwargs): # real signature unknown 9""" 10 Add an element to a set. #添加元素 11 12 This has no effect if the element is already present. 13""" 14 pass 15 16 def clear(self, *args, **kwargs): # real signature unknown 17""" Remove all elements from this set. """ #清除所有元素 18 pass 19 20 def copy(self, *args, **kwargs): # real signature unknown 21""" Return a shallow copy of a set. """ #浅拷贝 22 pass 23 24 def difference(self, *args, **kwargs): # real signature unknown 25""" 26 Return the difference of two or more sets as a new set. #a中存在,b中不存在 27 28 (i.e. all elements that are in this set but not the others.) 29""" 30 pass 31 32 def difference_update(self, *args, **kwargs): # real signature unknown 33""" Remove all elements of another set from this set. 从当前集合中删除和B中相同的元素""" 34 pass 35 36 def discard(self, *args, **kwargs): # real signature unknown 37""" 38 Remove an element from a set if it is a member. 移除指定元素,不存在不报错 39 40 If the element is not a member, do nothing. 41""" 42 pass 43 44 def intersection(self, *args, **kwargs): # real signature unknown 45""" 46 Return the intersection of two sets as a new set. 交集 47 48 (i.e. all elements that are in both sets.) 49""" 50 pass 51 52 def intersection_update(self, *args, **kwargs): # real signature unknown 53""" Update a set with the intersection of itself and another. 取交集并更新到a中 """ 54 pass 55 56 def isdisjoint(self, *args, **kwargs): # real signature unknown 57""" Return True if two sets have a null intersection. 如果没有交集,返回True """ 58 pass 59 60 def issubset(self, *args, **kwargs): # real signature unknown 61""" Report whether another set contains this set. 是否是子序列 """ 62 pass 63 64 def issuperset(self, *args, **kwargs): # real signature unknown 65""" Report whether this set contains another set. 是否是父序列""" 66 pass 67 68 def pop(self, *args, **kwargs): # real signature unknown 69""" 70 Remove and return an arbitrary set element. 移除元素 71 Raises KeyError if the set is empty. 72""" 73 pass 74 75 def remove(self, *args, **kwargs): # real signature unknown 76""" 77 Remove an element from a set; it must be a member. 移除指定元素,不存在保错 78 79 If the element is not a member, raise a KeyError. 80""" 81 pass 82 83 def symmetric_difference(self, *args, **kwargs): # real signature unknown 84""" 85 Return the symmetric difference of two sets as a new set. 对称差集,a有b没有 + b有a没有 86 87 (i.e. all elements that are in exactly one of the sets.) 88""" 89 pass 90 91 def symmetric_difference_update(self, *args, **kwargs): # real signature unknown 92""" Update a set with the symmetric difference of itself and another. """ 对称差集,并更新到a中 93 pass 94 95 def union(self, *args, **kwargs): # real signature unknown 96""" 97 Return the union of sets as a new set. 并集 98 99 (i.e. all elements that are in either set.) 100"""101 pass 102103 def update(self, *args, **kwargs): # real signature unknown104""" Update a set with the union of itself and others. 更新,一般把一个list通过迭代方式更新到set集群中"""105 pass
原文:http://www.cnblogs.com/chhphjcpy/p/6067549.html
内容总结
以上是互联网集市为您收集整理的014-python基础-set集合全部内容,希望文章能够帮你解决014-python基础-set集合所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。