Python基础学习-08
my_set = {"小呆呆", "小菲菲", "小羊羊"}
print(my_set)
for i in my_set:
print(i)
print("超人强" in my_set)
my_set_1 = {"小呆呆", "小菲菲", "小羊羊", "迷糊老师"}
my_set.update(my_set_1)
print(my_set)
my_set_2 = ['喜羊羊', '懒羊羊']
my_set.update(my_set_2)
print(my_set)
A = {"小呆呆", "小菲菲", "小羊羊", "迷糊老师"}
A.remove('小羊羊')
print(A)
A = {"小呆呆", "小菲菲", "小羊羊", "迷糊老师"}
A.discard("小狼狼")
print(A)
A.pop()
print(A)
A.clear()
print(A)
del A
my = {"小呆呆", "小菲菲", "小羊羊", "迷糊老师"}
for i in my:
print(i)
set1 = {"a", "b", "c"}
set2 = {1, 2, 3}
set3 = set1.union(set2)
print(set3)
set1 = {"a", "b", "c"}
set2 = {1, 2, 3}
set1.update(set2)
print(set1)
my = {"1", "2", "3"}
you = {"1", "3", "4"}
my.intersection_update(you)
print(my)
my = {"1", "2", "3"}
you = {"1", "3", "4"}
z = my.intersection(you)
print(z)
my = {"1", "2", "3"}
you = {"1", "3", "4"}
my.symmetric_difference_update(you)
print(my)
my = {"1", "2", "3"}
you = {"1", "3", "4"}
z = my.symmetric_difference(you)
print(z)
fruits = {"apple", "banana", "cherry"}
if "apple" in fruits:
print("Yes, apple is a fruit!")
fruits = {"apple", "banana", "cherry"}
test = {"apple", "banana", "cherry", "orange"}
fruits.update(test)
print(fruits)
fruits = {"apple", "banana", "cherry"}
more_fruits = ["orange", "mango", "grapes"]
fruits.update(more_fruits)
print(fruits)
fruits = {"apple", "banana", "cherry"}
fruits.remove("banana")
print(fruits)
fruits = {"apple", "banana", "cherry"}
fruits.discard("香蕉")
print(fruits)
|