File tree Expand file tree Collapse file tree 1 file changed +58
-0
lines changed
Expand file tree Collapse file tree 1 file changed +58
-0
lines changed Original file line number Diff line number Diff line change 1+ # 4-2 Python 内置函数
2+ python 的内置函数有很多,大家可以自行百度一下,因为实在是太多了,没法一一进行举例介绍,大家也没有必要全部记住,只要有个大概的印象
3+
4+ 在项目的实战中,再自行百度去了解实际的用法
5+
6+ 下面咱们简单介绍几个内置函数的用法
7+
8+ - len(value) 返回一个字符串的找度
9+ - max(value) 返回字符串中的最大的字母
10+ - min(value) 返回字符串中最小的字母
11+ - abs(value) 取一个数的绝对值
12+ - round(value, n) 对一个数字进行四舍五入,并保留n位小数
13+ ### 代码区 1
14+ ``` python
15+ 1 value = ' python'
16+
17+ 2 print (' 我共有' , len (value), ' 个字符' )
18+
19+ 3
20+ ```
21+ ![ 4] ( https://user-images.githubusercontent.com/103555341/163546933-bee710b5-943e-454e-b00d-922d2b897614.jpg )
22+ ``` python
23+ 我共有 6 个字符
24+ ```
25+ ### 代码区 2
26+ ``` python
27+ 1 x = 3.1415926
28+ 2 # 四舍五入保留3位小数
29+ 3 print (round (x, 3 ))
30+ 4 # 四舍五入保留2位小数
31+ 5 print (round (x, 2 ))
32+ 6
33+ ```
34+ ![ 4] ( https://user-images.githubusercontent.com/103555341/163546933-bee710b5-943e-454e-b00d-922d2b897614.jpg )
35+ ``` python
36+ 3.142
37+ 3.14
38+ ```
39+ ### 代码区 3
40+ ``` python
41+ 1 # 练习题 把上面的函数演练一遍
42+ 2
43+ ```
44+ ![ 4] ( https://user-images.githubusercontent.com/103555341/163546933-bee710b5-943e-454e-b00d-922d2b897614.jpg )
45+
46+
47+
48+
49+
50+
51+
52+
53+
54+
55+
56+
57+
58+
You can’t perform that action at this time.
0 commit comments