版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/DreamHome_S/article/details/79848502
Python之set集合操作
创建集合
>>> a = set('boy')
a = {'b','o','y'}
集合添加
add 方法
把要传入的元素做为一个整个添加到集合中
>>> a.add('python') a = {'b','o','y','python'}
update 方法
把要传入的元素拆分,做为个体传入到集合中
>>> a.update('python') a = {'b','o','y','p','t','h','n'}
集合删除
remove方法
a.remove('b')
集合操作
注:集合不支持索引访问
操作符号列表
含义 | python |
---|---|
差集 | -/difference() |
交集 | &/intersection |
并集 | |/union |
不等于 | != |
等于 | == |
属于 | in |
不属于 | not in |