一:概念
集合是无序可变,元素不能重复;实际上,集合的底层是字典实现,集合中的所有元素都是字典中的‘键对象’,因此是不能重复且唯一的。
二:集合的创建和删除
2.1 使用{}创建集合对象,并使用add()方法添加元素

2.2 使用set()
set()将列表,元组等可迭代对象转成集合,如果原来数据存在重复元素,则只保留一个

2.3 删除
1.remove()删除指定元素
2.clear()清空整个集合

3.集合的相关操作

集合是无序可变,元素不能重复;实际上,集合的底层是字典实现,集合中的所有元素都是字典中的‘键对象’,因此是不能重复且唯一的。
set()将列表,元组等可迭代对象转成集合,如果原来数据存在重复元素,则只保留一个
1.remove()删除指定元素
2.clear()清空整个集合
本文标题:六:Python序列之集合
本文链接:https://www.haomeiwen.com/subject/sdyeuhtx.html
网友评论