编程模式: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也叫做位置参数实参:实际存在,占用空间形参:不占空间关键参数,不能写在位置参数前面!!!!!!!··························
时间: 2024-11-10 18:37:34