PyTricks:Functions are first-class citizens in Python

函数在python中是first-class citizens:
1.能作为其他函数的参数被传递
2.能从其他函数中作为值返回
3.能够分配成变量且存储在数据结构中

示例:

Python 3.6.0 (default, Oct 21 2017, 01:22:56)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> def myfunc(a,b):
...     return a+b
...
>>> funcs=[myfunc]
>>> funcs[0]
<function myfunc at 0x7fdd6a27ae18>
>>> funcs[0](2,3)
5

【什么是First-class citizen?】–摘自first-class citizens wiki百科
  In programming language design, a first-class citizen (also type, object, entity, or value) in a given programming language is an entity which supports all the operations generally available to other entities. These operations typically include being passed as an argument, returned from a function, and assigned to a variable.
  在编程语言设计中,在一个给定的编程语言里first-class citizen(也可以是类型,对象,实体或值)是一个实体(支持所有通常可用于其他实体的操作)。这些操作典型地包括作为参数被传递,从函数返回,并将其分配给一个变量。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值