1.定义函数封装:
def 函数名():
函数中的代码
函数中的代码
def这行代码最后需要冒号
2.存在冒号就需要换行缩进
3.处于def 缩进中的代码,称为函数体
举例:
def say_hello():
print("hello")
print('hi')
print('你好!')
say_hello()
2.函数调用:函数调用,就是使用函数名字去执行函数中的代码
函数名字()下面有
3.局部变量和全局变量:如下图
Python,定义函数,函数封装及调用函数, 函数局部变量和全局变量
阅读 114
2022-04-13
1.定义函数封装:
def 函数名():
函数中的代码
函数中的代码
def这行代码最后需要冒号
2.存在冒号就需要换行缩进
3.处于def 缩进中的代码,称为函数体
举例:
def say_hello():
print("hello")
print('hi')
print('你好!')
say_hello()
2.函数调用:函数调用,就是使用函数名字去执行函数中的代码
函数名字()下面有
3.局部变量和全局变量:如下图
相关推荐
精彩评论(0)