How to write a simple callback function?

前端 未结 6 1943
我在风中等你
我在风中等你 2021-02-04 06:11

Python 2.7.10

I wrote the following code to test a simple callback function.

def callback(a, b):
    print(\'Sum = {0}\'.format(a+b))

def main(         


        
6条回答
  •  长情又很酷
    2021-02-04 06:16

    Your code is executed as follows:

    main(callback(1, 2))
    

    callback function is called with (1, 2) and it returns None (Without return statement, your function prints Sum = 3 and returns None)

    main function is called with None as argument (So callback != None will always be False)

提交回复
热议问题