Python Basics-adorners

Source: Internet
Author: User

defTraet (CHARACTER_TRAET):#Pass the module to be executed from here        defInner (*args, * *Kwargs): Character_traet (*args, **kwargs)#invoke the appropriate function        returnInner#when the user calls treat, only the memory address of the inner is returned, and the next time it is added (), the inner function is executed .@traetdefNurse (NAI):Print("Treatment Form Nurse%s"%nai) @traetdefMonk ():Print("treatment from Monk")defArcher ():Print("This is a archer the can not treat") Monk () Nurse ("Nainai")#here is equivalent to nurse = traet (nurse) nurse ("Nainai") you're here to replace the nurse function.#results: Treatment from Monk#treatment Form Nurse Nainai

Adorners, as described in order to decorate other functions (adding new functionality), are also functions.

A principle of "open-closed" principle in software development, in simple terms, it stipulates that the function code that has been implemented is not allowed to be modified, but can be extended. The decorator was sent at this time.

Python Basics-adorners

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.