什么是"拉姆达结合"在Python? [英] What is "lambda binding" in Python?

查看:189
本文介绍了什么是"拉姆达结合"在Python?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我明白了什么是lambda函数在Python,但我找不到什么是拉姆达约束力通过搜索Python文档的含义。
链接阅读有关这将是巨大的。
以下是一个小例子说明会更好。
谢谢你。

I understand what are lambda functions in Python, but I can't find what is the meaning of "lambda binding" by searching the Python docs. A link to read about it would be great. A trivial explained example would be even better. Thank you.

推荐答案

首先,一般的定义:

当某个程序或功能的语句
  被执行时,当前值
  形式参数保存(在
  栈)和的范围内
  声明中,他们被绑定到
  在做实际的参数值
  呼叫。当语句
  退出时,这些的原始值
  正式的参数恢复。这个
  协议是完全递归的。如果内
  语句的身体,是东西
  做到这一点导致形式参数
  再次结合,为新值,该
  拉姆达约束力的计划保证
  这一切发生在一个有序
  方式。

When a program or function statement is executed, the current values of formal parameters are saved (on the stack) and within the scope of the statement, they are bound to the values of the actual arguments made in the call. When the statement is exited, the original values of those formal arguments are restored. This protocol is fully recursive. If within the body of a statement, something is done that causes the formal parameters to be bound again, to new values, the lambda-binding scheme guarantees that this will all happen in an orderly manner.

现在,有关于Lambda\"> Python的例子极好

Now, there is an excellent python example in a discussion here:

...只有一个 X 绑定:做 X = 7 只是改变在价值在pre-现有绑定。这就是为什么

"...there is only one binding for x: doing x = 7 just changes the value in the pre-existing binding. That's why

def foo(x): 
   a = lambda: x 
   x = 7 
   b = lambda: x 
   return a,b

返回两个函数都返回7;如果有一个新的绑定在在x = 7 ,该函数将返回不同的值[假设你不调用(7),当然富。同时假设nested_scopes] ......

returns two functions that both return 7; if there was a new binding after the x = 7, the functions would return different values [assuming you don't call foo(7), of course. Also assuming nested_scopes]...."

这篇关于什么是"拉姆达结合"在Python?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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