求a_set = set([8, 9, 10, 11, 12, 13])和b_set = {0, 1, 2, 3, 7, 8}的交集,并集,差集,对称差集
时间: 2023-10-07 21:05:35 浏览: 45
a_set = set([8, 9, 10, 11, 12, 13])
b_set = {0, 1, 2, 3, 7, 8}
交集:a_set.intersection(b_set) 或 a_set & b_set,输出结果为 {8}
并集:a_set.union(b_set) 或 a_set | b_set,输出结果为 {0, 1, 2, 3, 7, 8, 9, 10, 11, 12, 13}
差集:a_set.difference(b_set) 或 a_set - b_set,输出结果为 {9, 10, 11, 12, 13}
对称差集:a_set.symmetric_difference(b_set) 或 a_set ^ b_set,输出结果为 {0, 1, 2, 3, 7, 9, 10, 11, 12, 13}
阅读全文