提交 88ede8e5 编写于 作者: 檀越@新空间's avatar 檀越@新空间 🐭

fix:定义集合

上级 2d4e4314
......@@ -4,13 +4,13 @@
# 定义集合
my_set = {"传智教育", "黑马程序员", "itheima", "传智教育", "黑马程序员", "itheima", "传智教育", "黑马程序员", "itheima"}
my_set_empty = set() # 定义空集合
my_set_empty = set() # 定义空集合
print(f"my_set的内容是:{my_set}, 类型是:{type(my_set)}")
print(f"my_set_empty的内容是:{my_set_empty}, 类型是:{type(my_set_empty)}")
# 添加新元素
my_set.add("Python")
my_set.add("传智教育") #
my_set.add("传智教育") #
print(f"my_set添加元素后结果是:{my_set}")
# 移除元素
my_set.remove("黑马程序员")
......@@ -32,7 +32,6 @@ print(f"取出差集后的结果是:{set3}")
print(f"取差集后,原有set1的内容:{set1}")
print(f"取差集后,原有set2的内容:{set2}")
# 消除2个集合的差集
set1 = {1, 2, 3}
set2 = {1, 5, 6}
......@@ -59,6 +58,3 @@ print(f"集合内的元素数量有:{num}个")
set1 = {1, 2, 3, 4, 5}
for element in set1:
print(f"集合的元素有:{element}")
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册