Skip to content

Commit a25c653

Browse files
authored
Create kc43.md
1 parent 0ab687b commit a25c653

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

kc/kc43.md

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# 4-3 python库的使用和标准库介绍
2+
python之所以在当前在互联网领域占有很大的领域,主要就在于,他优秀丰富的库
3+
4+
库可以理解为,一个专项技能包, 如果代码中需要用到某一项功能,就需要先导入这个技能包
5+
6+
python导入一个库,可以用import .. 或者 from .. import 关键字来操作
7+
8+
- import 导入整个库
9+
- from .. import 导入库文件中的指定元素
10+
11+
下面,通过代码来看一下导入库的用法
12+
### 代码区 1
13+
```python
14+
1 # 导入一个数学类型库 math库,提供了大量数学去处相关的函数
15+
2 import math
16+
3
17+
4 # 打印一个派的值
18+
5 print(math.pi)
19+
6
20+
7 # 小数取整
21+
8
22+
9 print(math.trunc(math.pi))
23+
```
24+
![4](https://user-images.githubusercontent.com/103555341/163546933-bee710b5-943e-454e-b00d-922d2b897614.jpg)
25+
```python
26+
3.141592653589793
27+
3
28+
```
29+
### 代码区 2
30+
```python
31+
1 # 同样,上面的方法,也可以这样写,这样,只导出了pi这个常量,当你要用math库中的其它函时,是会报错的,需要在import后面,一一写出
32+
2 from math import pi, trunc
33+
3
34+
4 print(pi)
35+
5
36+
6 print(trunc(pi))
37+
7
38+
```
39+
![4](https://user-images.githubusercontent.com/103555341/163546933-bee710b5-943e-454e-b00d-922d2b897614.jpg)
40+
```python
41+
3.141592653589793
42+
3
43+
```
44+
### 代码区 3
45+
```python
46+
1 # 练习题 把上面的代码,试一遍吧
47+
2
48+
```
49+
![4](https://user-images.githubusercontent.com/103555341/163546933-bee710b5-943e-454e-b00d-922d2b897614.jpg)
50+
51+
52+
53+
54+
55+
56+
57+
58+
59+

0 commit comments

Comments
 (0)