在计算机程序设计中,回调函数,或简称回调(Callback),是指通过函数参数传递到其它代码的,某一块可执行代码的引用。这一设计允许了底层代码调用在高层定义的子程序。
有两种类型的回调函数:即blocking callbacks (also known as synchronous callbacks or just callbacks) and deferred callbacks (also known as asynchronous callbacks).
那么,在python中如何实现回调函数呢,看代码:
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)
谢谢阅读,希望能帮到大家!