First-Class Functions

  • First class like Integers, strings, and dictionaries

  • Higher-Order Functions: A function that takes a function as
    argument or returns a function as the result

    • most common: map, filter, reduce, apply

    • python equvalent: list comprehsive, (sum, all, any), ‘*, **’

  • anonymous function: keyword lambda

  • Callable Object

    • use callable() built-in to determine

    • functions, methods, class(__new__, __init__), class
      instances(__call__), generator functions

    • implement __call__ to create function-like objects that have
      some internal state

  • Attributes of user-defined functions

    • __anaotations__, __name__, __qualname__

    • __call__, __get__

    • __defaults__, __kwdefaults__ …

  • From Positional to Keyword-Only Parameters

    • specify keyword-only arguments

    • specify var-lenght positional and kw arguments

  • use inspect module to extract the function signature

  • The operator Module

  • functools Module

    • partial: produces a new callable with some of the arguments of
      the original function fixed

本文地址:https://blog.csdn.net/qq_41719597/article/details/110850385