码迷,mamicode.com
首页 > 编程语言 > 详细

python3_set方法

时间:2017-09-17 17:36:00      阅读:215      评论:0      收藏:0      [点我收藏+]

标签:span   elf   self   str   并集   inter   form   差集   __iter__   

>>> s={s,s,t}
>>> s
{s, t}
>>> type(s)
<class set>
>>>
>>> s=set([1,2,3,4,5,6,7])
>>> s
{1,

>>> dir(set())
[__and__, __class__, __contains__, __delattr__, __dir__, __doc__, __eq__, __format__, __ge__, __getattribute__, __gt__, __hash__, __iand__, __init__, __init_subclass__, __ior__, __isub__, __iter__, __ixor__, __le__, __len__, __lt__, __ne__, __new__, __or__, __rand__, __reduce__, __reduce_ex__, __repr__, __ror__, __rsub__, __rxor__, __setattr__, __sizeof__, __str__, __sub__, __subclasshook__, __xor__, add, clear, copy, difference, difference_update, discard, intersection, intersection_update, isdisjoint, issubset, issuperset, pop, remove, symmetric_difference, symmetric_difference_update, union, update]
>>>

add添加, clear清空, copy复制, difference差异(清除), difference_update清除更新, discard移除, intersection交集, intersection_update交集更新, isdisjoint无交集, issubset子集, issuperset父集, pop移除, remove移除, symmetric_difference差集, symmetric_diffeence_update减, union并集, update更新



add(self, *args, **kwargs): 
>>> s=set()
>>> s.add(gg)
>>> s
{gg}
>>>

clear(self, *args, **kwargs): 
>>> s={a,g}
>>> s
{g, a}
>>> s.clear()
>>> s
set()
>>>


copy(self, *args, **kwargs): 
>>> s={s}
>>> s1=s.copy()
>>> s1
{s}
>>>

difference(self, *args, **kwargs): 
>>> s0={"a",b,c}
>>> s1={b,c,d}
>>> s0
{c, a, b}
>>> s1
{c, d, b}
>>> s0.difference(s1)
{a}
>>>

difference_update(self, *args, **kwargs): 
>>> s0={"a",b,c}
>>> s1={b,c,d}
>>> s0.difference_update(s1)
>>> s0
{a}

discard(self, *args, **kwargs): 
>>> s=set(agsgasf)
>>> s
{s, g, a, f}
>>> s.discard(s)
>>> s
{g, a, f}
>>>

intersection(self, *args, **kwargs): 
>>> s
{g, a, f}
>>> s.intersection(set(afh))
{a, f}
>>>

intersection_update(self, *args, **kwargs): 
>>> s
{g, a, f}

>>> s.intersection_update(set(afh))
>>> s
{a, f}
>>>

isdisjoint(self, *args, **kwargs): 
>>> s
{a, d, s, f}
>>> s.isdisjoint(c)
True
>>>

issubset(self, *args, **kwargs): 
>>> s
{a, d, s, f}
>>> s.issubset(adsfg)
True
>>>

issuperset(self, *args, **kwargs): 
>>> s
{a, d, s, f}
>>> s.issuperset(a)
True
>>>

pop(self, *args, **kwargs): 
>>> s
{a, d, s, f}
>>> s.pop()
a
>>> s
{d, s, f}
>>>

remove(self, *args, **kwargs): 
>>> s
{d, s, f}
>>> s.remove(s)
>>> s
{d, f}
>>>

symmetric_difference(self, *args, **kwargs): 
>>> s
{a, s, f}
>>> s.symmetric_difference(s)
{a, f}
>>>

symmetric_difference_update(self, *args, **kwargs): 
>>> s
{s, f}
>>> s.symmetric_difference_update(s)
>>> s
{f}
>>>

union(self, *args, **kwargs): 
>>> s
{f}
>>> s.union(sfsghj)
{h, s, f, j, g}
>>>


update(self, *args, **kwargs):
>>> s=set(abc)
>>> s.update(bd)
>>> s
{a, d, b, c}
>>>

 

python3_set方法

标签:span   elf   self   str   并集   inter   form   差集   __iter__   

原文地址:http://www.cnblogs.com/wmxuan/p/7536121.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!