How to write a simple callback function?

前端 未结 6 2006
我在风中等你
我在风中等你 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:29

    Here's what you wanted to do :

    def callback(a, b):
        print('Sum = {0}'.format(a+b))
    
    def main(a,b,f=None):
        print('Add any two digits.')
        if f != None:
            f(a,b)
    
    main(1, 2, callback)
    

提交回复
热议问题