欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

流畅的python First-Class Functions

程序员文章站 2022-07-08 15:48:23
First-Class FunctionsFirst class like Integers, strings, and dictionariesHigher-Order Functions: A function that takes a function asargument or returns a function as the resultmost common: map, filter, reduce, applypython equvalent: list compr...

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

相关标签: python