集合 数据拷贝 运算符
集合
无序
-
其中的元素是唯一的
-
Set = set()
Set =
-
逻辑运算
交集:1&2
对称差集:1^2 (集合中不同的元素)
并集:1|2
差集:1-2 (集合1包含但集合2不包含的)
- 列表去重
l = [.....]-->指一个列表
l = set(l) 转为集合
l = list(l) 再转为列表 就ok了
数据拷贝(copy())
L1 = [1, 2]
L2 = L1
L2[0] = 6
print(L1)
print(L2)
"""
[6, 2]
[6, 2]
"""
为了防止这种情况发生,就要拷贝
浅拷贝:把L1拷贝到L2中,L2=L1.copy()
深拷贝:L2=L1.deepcopy()
运算符
逻辑
and(与),or(或),not(非)
A and B:A为False,结果为False,否则返回B的值
A or B:ATtrue,返A,否则返B
A not B:A为True,返False,否则返True
位
返回1或0
&(与),|(或),^(异),
~(按位取反,把数据的二进制取反,0-->1,1-->0)
<<,>>
成员运算符
...in... (...在...):判断是否属于成员,返回True或False
...not in...
身份运算符
用于比较两个标识符所引用对象的存储单位(内存地址)
is或is not

浙公网安备 33010602011771号