当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Python set clear()用法及代码示例


clear()方法从集合中删除所有元素。

用法:

set.clear()
parameters:
The clear() method doesn't take any parameters.
返回:
The clear() method doesn't return any value.
# set of letters 
GEEK = {'g', 'e', 'e', 'k', 's'} 
print('GEEK before clear:', GEEK) 
  
# clearing vowels 
GEEK.clear() 
print('GEEK after clear:', GEEK)

输出:


GEEK before clear:set(['s', 'e', 'k', 'g'])
GEEK after clear:set([])

应用:

It is used to clear set.
# set of letters 
GEEK = {6, 0, 4, 1} 
print('GEEK before clear:', GEEK) 
  
# clearing vowels 
GEEK.clear() 
print('GEEK after clear:', GEEK) 

输出:

GEEK before clear:set([0, 1, 4, 6])
GEEK after clear:set([])


相关用法


注:本文由纯净天空筛选整理自pawan_asipu大神的英文原创作品 set clear() in python。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。