这是我简单的演示while循环。
count = 0
while count < 5:
print 'The count is:', count
count = count + 1
现在我想使用lambdas更改正常的while循环。
def func():
count = 0
print 'The count is:', count
count += 1
a = lambda count: (count < 5 and func() )
print a
我做错了什么?
您的代码有很多错误,我认为lambda
不应在没有返回值的情况下调用另一个函数。如果必须这样做,它将像:
def func(n):
i = 0
while i < n:
print 'The count is:', i
i += 1
a = lambda count: func(count)
a(5)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句