【发布时间】:2020-05-12 14:42:34
【问题描述】:
#to add and multiply numbers using lambda in python
a=int(input("a number: "))
b=int(input("another number: "))
print("the sum is {}".format(lambda a,b:a+b))
print("the multiple is {}".format(lambda a,b:a*b))
我尝试使用 lambda 将两个数字相加和相乘,但我不知道为什么它会显示这样的错误。我是编程初学者 错误是:
the sum is <function <lambda> at 0x000001B6BF941B88>
the multiple is <function <lambda> at 0x000001B6BF893798>
【问题讨论】:
-
因为
lambda是一个函数。你实际上需要调用它来获得一个值......你为什么在这里使用lambda?你可以做(lambda a,b: a+b)(a,b)但这只是做a + b的笨拙方式... -
什么是 lambdas for?只需使用
a+b和a*b。
标签: python python-3.x function lambda