提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
文章目录
- 函数入门
函数入门
1. 函数的概念



内置函数:https://docs.python.org/zh-cn/3.13/library/functions.html
模块提供的函数:https://docs.python.org/zh-cn/3.13/py-modindex.html

2.基本使用





3.参数

















4.返回值



5.全局作用域 VS 局部作用域



python
# 全局作用域 与 局部作用域,以及global的使用
a = 100
b = 200
def test():
c = '尚硅谷'
d = '你好啊'
global a
a = 300
print('函数中的打印(a)', a)
print('函数中的打印(b)', b)
print('函数中的打印(c)', c)
print('函数中的打印(d)', d)
test()
print('***************')
print('全局的打印(a)', a)
print('全局的打印(b)', b)
print(c)
print(d)



6.嵌套调用
嵌套调用:在一个函数执行的过程中,调用了另外一个函数,例如下面的代码:
python
# 函数嵌套调用测试1
def greet(name, msg):
print(f'我叫{name},我想说的话在下面:')
speak(msg)
print('嗯,我想说的结束了')
def speak(msg):
print('----------')
print(msg)
print('----------')
greet('张三', '你好啊')
# 函数嵌套调用测试2
def test1():
print('进入 test1 函数')
test2()
print('退出 test1 函数')
def test2():
print('进入 test2 函数')
test3()
print('退出 test2 函数')
def test3():
print('进入 test3 函数')
print('***正在执行 test3 函数')
print('退出 test3 函数')
test1()

7.递归调用




8.函数说明文档

