标签:指定元素 存在 pre 列表 set 拷贝 去重 sep png
print("alex", "dabai", "liu", sep = "")
1.可变:列表,字典
2.不可变:字符串, 数字, 元组
修改了变量的值,而id号跟着改变,即不可变类型
name = ‘alex‘ print(id(name)) name = ‘sb‘ print(id(name))
1.顺序访问:字符串, 列表, 元组
2.映射:字典
3.直接访问:数字
存放元素个数:
容器类型:列表,元组, 字典
原子:数字,字符串
1.不同的元素组成
2.无序
3.集合中元素必须是不可变类型
s = {1, 2, 3, 4, 5}
s = set(‘hello‘) print(s) s1 = set(["alex", "alex", "sb"]) print(s1)
s = {1, 2, 3, 4, 5, 6} s.add(‘alex‘) print(s)
s.clear()
s1 = s.copy()
s = {1, 2, 3, 4, 5, 6} v = s.pop() print(s,v)
s = {1, 2, 3, 4, 5, 6} s.remove(3) print(s)
s = {1, 2, 3, 4, 5, 6} s.discard(5) print(s)
s1 = {1, 2, 3} s2 = {2, 3, 4, 6} n = s1.intersection(s2) print(n)
s1 = {1, 2, 3} s2 = {2, 3, 4, 6} n = s1 & s2 print(n)
s1 = {1, 2, 3} s2 = {2, 3, 4, 6} n = s1.union(s2) print(n)
s1 = {1, 2, 3} s2 = {2, 3, 4, 6} n = s1 | s2 print(n)
s1 = {1, 2, 3} s2 = {2, 3, 4, 6} n = s1.difference(s2) print(n)
s1 = {1, 2, 3} s2 = {2, 3, 4, 6} n = s1 - s2 print(n)
s1 = {1, 2, 3} s2 = {2, 3, 4, 6} n = s1.symmetric_difference(s2) print(n)
s1 = {1, 2, 3} s2 = {2, 3, 4, 6} n = s1 ^ s2 print(n)
s1 = {1, 2, 3} s2 = {2, 3, 4, 6} s1.difference_update(s2) s1 = s1 - s2 print(s1) print(s1)
s1 = {1, 2, 3} s2 = {1, 2, 3, 4, 6} n = s1.issubset(s2) print(n)
s1 = {1, 2, 3} s2 = {1, 2, 3, 4, 6} n = s2.issuperset(s1) print(n)
s1 = {1, 2, 3} s2 = {1, 2, 3, 4, 6} s1.update(s2) print(s1)
s = frozenset("hello dabai") print(s)
标签:指定元素 存在 pre 列表 set 拷贝 去重 sep png
原文地址:https://www.cnblogs.com/dabai123/p/10984879.html