Python中的头等功能是什么? [英] What is first class function in Python

查看:135
本文介绍了Python中的头等功能是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我仍然对头等功能是什么感到困惑。如果我理解正确,第一类函数应该使用一个函数作为对象。这是正确的吗?

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 this correct?

这是一个头等功能

def this_is_example(myarg1):
    return myarg1

def this_is_another_ example(myarg):
     return this_is_example(myarg)+myarg

this_is_another_ example(1)


推荐答案

一级函数不是一种特殊的函数。 Python中的所有函数都是一流的函数。要说功能是某种编程语言中的第一类,意味着它们可以被传递和操作,类似于传递和操纵其他类型对象(如整数或字符串)的方式。您可以将一个函数分配给一个变量,将其作为参数传递给另一个函数等。区别并不是单个函数可以是第一类,也可以不是,但是整个语言可能将函数视为第一类对象,或者可能不会。

A first-class function is not a particular kind of function. All functions in Python are first-class functions. To say that functions are first-class in a certain programming language means that they can be passed around and manipulated similarly to how you would pass around and manipulate other kinds of objects (like integers or strings). You can assign a function to a variable, pass it as an argument to another function, etc. The distinction is not that individual functions can be first class or not, but that entire languages may treat functions as first-class objects, or may not.

这篇关于Python中的头等功能是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆