Python functions as objects

Source: Internet
Author: User

5th Chapter

1.first-class function

The first-class here means that a function can act as an object and return in another function.

Metaclass programming also has the concept of first-class class, which means that a class can be created as an object in another class, returning

2. Function parameters

6th Chapter

Strategy and Command are similar in design mode, but the focus is different.

Strategy mode:

Focusing on the substitution of algorithms, the algorithm can be encapsulated as a function object, which can be replaced by a function object.

Command mode:

involving Invoker and receiver

Seventh Chapter

Always feel a bit around, see understand, write the time can not write, so back down these two classic wording

The classic notation of decorator without parameters

def decoratorfunctionname (func):    @functools. Wraps (func)    def wrapper (*args, **kwargs):        * * * Front code * * *        return func (*args, **kwargs)    return wrapper

  

The classic notation of decorator with parameters

def decoratorfunctionname (decoratorarguments):    def Decorator (func):        @functools. Wrapper (func)        def Wrapper (*args, **kwargs): The            decoratorarguments***            return func (*args, **kwargs) return can be used in the pre-built code        Wrapper    return Decorator

  

Python functions as objects

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.