Skip to content

Commit f7440d3

Browse files
authored
Merge pull request #13 from crowser/master
Update set.md
2 parents c7a4740 + d310480 commit f7440d3

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

Datatypes/set.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ set(['a', 'c', 'b', 4, 'd', 'e'])
5656

5757
## 删除元素
5858

59-
`remove()` 方法可以删除集合中的元素。
59+
`remove()` 方法可以删除集合中的元素, 但是删除不存在的元素,会抛出 KeyError,可改用 `discard()`
6060

6161
看看例子:
6262

@@ -67,10 +67,11 @@ set(['a', 'c', 'b', 'd'])
6767
>>> s.remove('a') # 删除元素 'a'
6868
>>> s
6969
set(['c', 'b', 'd'])
70-
>>> s.remove('e') # 删除不存在的元素,会抛出 KeyErro
70+
>>> s.remove('e') # 删除不存在的元素,会抛出 KeyError
7171
Traceback (most recent call last):
7272
File "<stdin>", line 1, in <module>
7373
KeyError: 'e'
74+
>>> s.discard('e') # 删除不存在的元素, 不会抛出 KeyError
7475
```
7576

7677
## 交集/并集/差集

0 commit comments

Comments
 (0)