Python callback function

Source: Internet
Author: User

1, what is the callback function, feel good complex?? What is the meaning of existence?

callback function: A function called by a function pointer. If you pass the pointer (address) of the function as an argument to another function, when the pointer is used to invoke the function it points to, we say this is a callback function.

As the following example 1: Source https://www.cnblogs.com/hainan-zhang/p/6222552.html

defClean1 (times):"""just pretend to sweep the floor. Param Times: Count return None"""    Print('sweep Times completed:', Times)defclean2 (times):"""pretend to wash the hood param times: Return:none"""    Print('Number of wash Hoods:', Times)defCall_clean (times,function_name):"""This is very important, that is, the business system of domestic companies, what business must be here to say this is the core of the implementation of the callback function param times: number param function_name: callback function name return: The result of the call functions 
    """    returnfunction_name (Times) Call_clean (10,CLEAN2)#Call_clean (10,clean2)

This example describes the use of callback functions, without indicating the meaning of the callback function. This is not as good as calling the Clean2 function directly 10 times.

Here's another one on the Internet, example 2:http://blog.csdn.net/ma52103231/article/details/61432120

Look a little confused, difficult, change a

classCallback:def __init__(self,instance,function_name): Self.instance=instance Self.function_name=function_namedefAction (self,params): Self.instance.__getattribute__(Self.function_name) (params)classTest:def __init__(self): SELF.CLB=NonedefRegister (SELF,CLB): SELF.CLB=CLBdefdo_test (self): params=[] self.clb.action (params)classApi:def __init__(self,test_instance): Test_instance.register (Callback (self,self.function.__name__))    deffunction (self,params):Print('function') T=Test () a=Api (t) t.do_test ()#function

Example 3:http://blog.csdn.net/ma52103231/article/details/61432120

Python callback function

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.