标签:集合 arp pre highlight erro move 使用 元素 对比
set中使用remove和discard都删除元素,用remove删除时如果元素在集合中没有会报错,而discard不会
c = set({‘1‘,‘2‘,‘3‘})
c
{‘1‘, ‘2‘, ‘3‘}
c.remove(‘1‘)
c
{‘2‘, ‘3‘}
c.remove(‘4‘)
KeyError: ‘4‘
对比discard
c = set({‘1‘,‘2‘,‘3‘})
c
{‘1‘, ‘2‘, ‘3‘}
c.discard(‘1‘)
c
{‘2‘, ‘3‘}
c.discard(‘4‘)
c
{‘2‘, ‘3‘}
标签:集合 arp pre highlight erro move 使用 元素 对比
原文地址:https://www.cnblogs.com/xiaodongsuibi/p/12163210.html