Python – call back

#callback
def test(arg):
#print(arg)
arg("hello") # function call
#arg(hello) to handle(data)

#定義一個回呼函式
def handle(data):
print(data)

test(handle)

def add(n1, n2, cb):
cb(n1+n2)

def handle1(result):
print("結果是: ", result )

def handle2(result):
print("English Result of Add is: ", result )

add(3, 4, handle1)
add(5, 6, handle2)

本篇發表於 python。將永久鍊結加入書籤。

發表迴響

您的電子郵件位址並不會被公開。 必要欄位標記為 *

*

您可以使用這些 HTML 標籤與屬性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>