入门知识七
元组:
tuple 元组,特点:不可变的列表
*** 元组如果只有一个元素,需要在末尾添加一个“,” ***
集合:
set 集合
不可哈希:python中的set集合进行数据存储的时候,需要对数据进行哈希计算,根据计算出来的哈希值进行存储数据
set集合要求存储的数据必须是可以进行哈希计算的。
可变的数据类型:list, dict, set
可哈希:不可变的数据类型 int,str,tuple,bool
(s = {} 是字典 不是空集合)
创建空集合:s = set()
创建空元组:t = tuple()
创建空列表:l = list()
创建空字符串:s = str()
集合中若想修改 只能先删除 再新增 例:
s1 = {0, 8, 3, 1}
s2 = {1, 0, 2, 6}
“取交集
>>> print(s1 & s2)
{0, 1}
>>> print(s1.intersection(s2))
{0, 1}”
“取并集
>>>print(s1 | s2)
{0, 1, 2, 3, 6, 8}
>>> print(s1.union(s2))
{0, 1, 2, 3, 6, 8}”
“取差集
>>> print(s1 - s2)
{8, 3}
>>> print(s1.difference(s2))
{8, 3}”



