sync from local backup

This commit is contained in:
chunyu
2026-08-05 23:59:15 +08:00
commit d48ec1747c
358 changed files with 34384 additions and 0 deletions
+45
View File
@@ -0,0 +1,45 @@
# 函数与模块
## 学习目标
- 理解函数的作用
- 掌握函数的定义和调用
- 了解模块的使用
## 定义函数
```python
def greet(name):
'''打招呼函数'''
return f"你好,{name}!"
# 调用函数
message = greet("小明")
print(message) # 输出:你好,小明!
```
## 参数类型
```python
# 默认参数
def power(base, exponent=2):
return base ** exponent
print(power(3)) # 9
print(power(2, 3)) # 8
```
## 导入模块
```python
import math
print(math.sqrt(16)) # 4.0
from random import randint
print(randint(1, 100))
```
## 动手练习
1. 编写计算圆面积的函数
2. 创建判断素数的函数
3. 使用 math 模块进行数学计算