What is first class function in Python

前端 未结 8 1246
情话喂你
情话喂你 2020-12-08 10:28

I am still confused about what first-class functions are. If I understand correctly, first-class functions should use one function as an object. Is

8条回答
  •  一生所求
    2020-12-08 11:17

    "First-Class Functions" (FCF) are functions which are treated as so called "First-Class Citizens" (FCC). FCC's in a programming language are objects (using the term "objects" very freely here) which:

    • Can be used as parameters
    • Can be used as a return value
    • Can be assigned to variables
    • Can be stored in data structures such as hash tables, lists, ...

    Actually, very roughly and simply put, FCF's are variables of the type 'function' (or variables which point to a function). You can do with them everything you can do with a 'normal' variable.

    Knowing this, both this_is_another_example(myarg) and this_is_example(myarg1) are First-Class Functions, since all functions are First-Class in certain programming languages.

提交回复
热议问题