Python开发【第四章】:函数剖析
一、Python函数剖析 1、函数的调用顺序 #!/usr/bin/env python # -*- coding:utf-8 -*- #-Author-Lian #函数错误的调用方式 def func(): #定义函数func() print("in the func") foo() #调用函数foo() func() #执行函数func() def foo(): #定义函数foo() print("in the foo") ###########打印输出########### #报错:函数foo没有定义 #NameError: name 'foo' is not defined #函数正确的调用方式 def func(): #定义函数func() print("in the func") foo() #调用函数foo() def foo(): #定义函数foo() print("in the foo") func() #执行函数func() ###########打印输出########### #in the func #in the foo 总结:被调用函数要在执行之前被定义 2、高阶函数 满足下列条件之一就可成函数为高阶函数 某一函数当做参数传入另一个函数中 函数的返回值包含一个或多个函数 刚才调用顺序中的函数稍作修改就是一个高阶函数 #高阶函数 def func():