lambda in Python: is it returning multiple values?
To begin with let’s just have look at the old school of lambda in Python. As we know, lambda x: return x**2 is exactly equivalent to def squared(x): return x**2 Now look at this >>> f1 = lambda x,y,z: x+1, y+1, z+1 >>> print(f1(1,1,1)) What will you get on the screen? A tuple of (2, 2, 2)? No. You get an error instead. Traceback (most recent call last): File "<pyshell#7>", line 1, in <module> print(f1(1,1,1)) TypeError: 'tuple' object is not callable</module> Now that the “returning part” of lambda is covering the contents before comma only, let’s explicitly add the brackets: ...