python 函数 函数 函数 def MyFirstFunction(): print('This is my first function!') MyFirstFunction() //调用函数 def MySecondFunction(): print(name+'I love you!!!'); MySecondFunction('fish');//调用函数 MySecondFunction('flower');//调用函数 MySecondFunction.__doc__ //打印文档 print.__doc__ def add(num1,num2): result=num1+num2; return result; add(1,2) //形参 实参 def back(): return [1,'小甲鱼',3.14]; back() //元组打包 返回多个值 //局部变量 全局变量 //不要在函数内部修改全局变量,否则会新建同名的局部变量 //global def mufun(): global count count=10 print(10) myfun() print(count) //函数嵌套 def fun1(): print('fun1() 正在被调用') def fun2(): print('fun2() 正在被调用') fun2() fun1() fun2() //wrong //闭包 def FunX(x): def FunY(y): return x * y return FunY FunX(8)(5)