Skip to content

Commit 8517707

Browse files
authored
Update 31.md
1 parent cd36035 commit 8517707

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

md/31.md

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,37 @@
99
返回一个set对象,集合内不允许有重复元素:
1010

1111
```python
12-
In [159]: a = [1,4,2,3,1]
12+
In [1]: a = [1,4,2,3,1]
1313

14-
In [160]: set(a)
15-
Out[160]: {1, 2, 3, 4}
14+
In [2]: set(a)
15+
Out[2]: {1, 2, 3, 4}
16+
17+
In [3]: b = set(a)
18+
19+
In [4]: b.add(5)
20+
21+
In [5]: b
22+
Out[5]: {1, 2, 3, 4, 5}
23+
24+
In [6]: b.pop()
25+
Out[6]: 1
26+
27+
In [7]: b
28+
Out[7]: {2, 3, 4, 5}
29+
30+
In [8]: b.pop()
31+
Out[8]: 2
32+
33+
In [9]: b
34+
Out[9]: {3, 4, 5}
35+
36+
# 注意pop删除集合内任意一个元素
37+
In [10]: help(b.pop)
38+
Help on built-in function pop:
39+
40+
pop(...) method of builtins.set instance
41+
Remove and return an arbitrary set element.
42+
Raises KeyError if the set is empty.
1643
```
1744

18-
<center>[上一个例子](30.md) [下一个例子](32.md)</center>
45+
<center>[上一个例子](30.md) [下一个例子](32.md)</center>

0 commit comments

Comments
 (0)