python 中如何删除集合中元素

 

1、内置函数remove

>>> a = set([100, 200, 300])
>>> a
{200, 100, 300}
>>> type(a)
<class 'set'>
>>> a.remove(200)     ## 内置函数remove删除指定元素
>>> a
{100, 300}

 

 

2、清空集合

>>> a
{100, 300}
>>> a.clear()        ## 清空集合
>>> a
set()

 

posted @ 2022-06-07 00:09  小鲨鱼2018  阅读(554)  评论(0编辑  收藏  举报