在计算机程序设计中,回调函数,或简称回调(Callback),是指通过函数参数传递到其它代码的,某一块可执行代码的引用。这一设计允许了底层代码调用在高层定义的子程序:
例如:
def my_callback(input):print "function my_callback was called with %s input" % (input,)
def caller(input, func):
func(input)
for i in range(5):
caller(i, my_callback)
执行结果是:
function my_callback was called with 0 inputfunction my_callback was called with 1 input
function my_callback was called with 2 input
function my_callback was called with 3 input
function my_callback was called with 4 input
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)