no message
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
# 无序,不可重复,可扩展
|
||||
# 不能通过索引访问元素
|
||||
# 自动去重
|
||||
# 元素必须是可哈希的(如 int, str, tuple),不能包含 list、dict、set 等可变类型
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
s = {1,2}
|
||||
s.add(3) # 添加元素
|
||||
print(s)
|
||||
@@ -0,0 +1,3 @@
|
||||
s = {1,2,3}
|
||||
s.remove(3) # 删除元素 若不存在则报 KeyError
|
||||
print(s)
|
||||
@@ -0,0 +1,3 @@
|
||||
s = {1,2,3}
|
||||
s.discard(3) # 删除元素 若不存在也不报错
|
||||
print(s)
|
||||
@@ -0,0 +1,3 @@
|
||||
s = {1,2,3}
|
||||
s.pop() # 随机弹出一个元素
|
||||
print(s)
|
||||
Reference in New Issue
Block a user