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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。