🆕 Add new test file basic_tests/set_test.py
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
set1 = {1, 2, 3, 3, 3, 2}
|
||||
print(set1)
|
||||
|
||||
set1 = {1, 2, 3, 4, 5, 6, 7}
|
||||
set2 = {2, 4, 6, 8, 10}
|
||||
|
||||
# 交集
|
||||
print("交集")
|
||||
print(set1 & set2) # {2, 4, 6}
|
||||
print(set1.intersection(set2)) # {2, 4, 6}
|
||||
|
||||
# 并集
|
||||
print("并集")
|
||||
print(set1 | set2) # {1, 2, 3, 4, 5, 6, 7, 8, 10}
|
||||
print(set1.union(set2)) # {1, 2, 3, 4, 5, 6, 7, 8, 10}
|
||||
|
||||
# 差集
|
||||
print("差集")
|
||||
print(set1 - set2) # {1, 3, 5, 7}
|
||||
print(set1.difference(set2)) # {1, 3, 5, 7}
|
||||
|
||||
# 对称差 (并集 - 交集)
|
||||
print("对称差")
|
||||
print(set1 ^ set2) # {1, 3, 5, 7, 8, 10}
|
||||
print(set1.symmetric_difference(set2)) # {1, 3, 5, 7, 8, 10}
|
||||
Reference in New Issue
Block a user