首页 > 代码库 > 函数笔记1

函数笔记1

编程模式:
1面向对象;特点:类;类用class定义
2面向过程;特点:过程;def定义
3函数式编程;特点:函数;def定义
······························
函数:
是逻辑结构化和过程化的一种编程方法。
···································
定义函数的方法:
def test(x):
"函数描述"
x+=1
return x

def 定义函数关键字
test 函数名
():内可定义形参
"文档描述"
x+=1 程序或者代码块
return x 定义返回值
·································
···过程是没有返回值的函数
····························
用函数的好处:
1.代码的重复利用
2.可扩展
3.保持一致性
································
return会终止函数的运行
赋值后,输出的值是return的返回值
···························
return
返回值=0:返回None
返回值=1:返回object
返回值>1:返回tuple
·····························
为什么要有返回值
想要返回的结果
·························
参数
1.形参和实参

def test(x,y):
print(x)
print(y)
test(1,2)
这里x,y叫做形参;1,2叫做实参,x,y也叫做位置参数
实参:实际存在,占用空间
形参:不占空间
关键参数,不能写在位置参数前面!!!!!!!
··························


函数笔记1