Python中的一等函数是什么 [英] What is first class function in Python

查看:23
本文介绍了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天全站免登陆