Lambda内部的Lambda [英] Lambda inside lambda
本文介绍了Lambda内部的Lambda的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
只是出于好奇.几天前发现了Lambdas.我很想知道是否可以做类似的事情:
Just for curiosity. Discovered Lambdas a few days ago. I was jus wondering if something like that can be done:
(尝试过解释,但我的尝试似乎都无效)
(Tried on the interpret but none of my tries seemed to work)
p = lambda x: (lambda x: x%2)/2
没有明确的目的.我只是找不到满意的答案.我可能误解了Lambda.
There's no explicit purpose. I just did'nt find a satisfactory answer. I may have misunderstood Lambdas.
推荐答案
您实际上不是在呼叫内部lambda
:
p = lambda x: (lambda x: x%2)(x)/2
请注意,在Python 2中,此示例将始终返回0
,因为除以2
的余数将是0
或1
,并且将结果除以2
的整数将导致截断的0
.
Note in Python 2 this example will always return 0
since the remainder from dividing by 2
will be either 0
or 1
and integer-dividing that result by 2
will result in a truncated 0
.
这篇关于Lambda内部的Lambda的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文