集合 set

 {1,2,3,4,5,6} - {3,4}
{1, 2, 5, 6}


{1,2,3,4,5,6}+{3,4}
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for +: 'set' and 'set'


 {1,2,3,4,5,6}  & {3,4}
{3, 4}


{1,2,3,4,5,6} | {3,4,7}
{1, 2, 3, 4, 5, 6, 7}

2.如何定义一个空的集合?

print(type({})) # 不能这样定义,这样定义的结果是:<class 'dict'>,这个表示一个空字典

#需要按照下面的这样的方式来定义一个空的集合
print(type(set()))
posted @ 2022-05-27 22:07  repinkply  阅读(12)  评论(0)    收藏  举报