在计算机程序设计中,回调函数,或简称回调(Callback),是指通过函数参数传递到其它代码的,某一块可执行代码的引用。这一设计允许了底层代码调用在高层定义的子程序
有两种类型的回调函数:
那么,在python中如何实现回调函数呢,看代码:
代码如下:
defmy_callback(input):
print"functionmy_callbackwascalledwith%sinput"%(input,)
defcaller(input,func):
func(input)
foriinrange(5):
caller(i,my_callback)