python集合的基本操作

python集合的基本操作

  • 特点:无序、唯一、不可变
  • 集合元素的添加
  1. add():添加单个元素
    python集合的基本操作
  2. update():添加集合
    python集合的基本操作
  • 集合元素的删除
  1. pop():弹出一个元素(由于集合是无序的所以无法指定索引进行删除)
    python集合的基本操作
  2. remove():指定删除集合中具体的元素
    python集合的基本操作
  3. clear():清空集合
    python集合的基本操作
  4. del:python内置的方法删除
    python集合的基本操作
  • 集合之间的数学运算
  1. 交集(& 或者 intersection)
    python集合的基本操作
  2. 并集(| 或者 union)
    python集合的基本操作
  3. 差集(- 或者 difference)
    python集合的基本操作
  4. 反交集(^ 或者 symmetric_difference)
    python集合的基本操作
  5. 子集(< 或者 issubset)
    python集合的基本操作
  6. 超集(> 或者 issuperset)
    python集合的基本操作