判断两个list是否相等
listA = [1,2,3]
listB = [1,2,3]
# True
print(listA == listB)
listA = [1,2,3]
listB = [3,2,1]
# False
print(listA == listB)
判断两个tuple是否相等
tupleA = (1,2,3)
tupleB = (1,2,3)
# True
print(tupleA == tupleB)
tupleA = (1,2,3)
tupleB = (3,1,3)
# False
print(tupleA == tupleB)
判断两个set是否相等
setA = {1, 2, 3}
setB = {1, 2, 3}
# True
print(setA == setB)
setA = {1, 2, 3}
setB = {3, 2, 1}
# True
print(setA == setB)
list转set
list = [1, 2, 3]
# [1, 2, 3]
print(list)
# {1, 2, 3}
setA = set(list)
print(setA)
list转tuple
list = [1, 2, 3]
# [1, 2, 3]
print(list)
# (1, 2, 3)
tupleA = tuple(list)
print(tupleA)
tuple转list
tupleA = (1, 2, 3)
# (1, 2, 3)
print(tupleA)
# [1, 2, 3]
listA = list(tupleA)
print(listA)
tuple转set
tupleA = (1, 2, 3)
# (1, 2, 3)
print(tupleA)
# {1, 2, 3}
setA = set(tupleA)
print(setA)
set转list
setA = {1, 2, 3}
# {1, 2, 3}
print(setA)
# [1, 2, 3]
listA = list(setA)
print(listA)
set转tuple
setA = {1, 2, 3}
# {1, 2, 3}
print(setA)
# (1, 2, 3)
tupleA = tuple(setA)
print(tupleA)
两个set集合的差集
setA = {1, 2, 3}
setB = {3, 4, 5}
# {1, 2}
print(setA - setB)
# {4, 5}
print(setB - setA)
网友评论