python 进阶学习之15

来源:互联网 发布:剃头理发器软件 编辑:程序博客网 时间:2024/06/05 04:37

集合类型

set()和 frozenset()

 >>> s=set('cheeseship')
>>> s=set('cheeseshop')
>>> s
set(['c', 'e', 'h', 'o', 'p', 's'])
>>> t=frozenset('bookshop')
>>> t
frozenset(['b', 'h', 'k', 'o', 'p', 's'])
>>> type(s)
<type 'set'>
>>> type(t)
<type 'frozenset'>
>>> len(s
... )
6

子集/超集
联合( | )  union()

交集( & ) intersection()

差补/相对补集( – ) difference()

对称差分( ^ ) symmetric_difference()

 

 

0 0
原创粉丝点击