3 ms·
You can do multiple lines, just not multiple statements: >>> f = lambda x: x * \ ... 20 >>> >>> f <function <lambda> at 0x7f8b69f2c6a8>
by fwip 6y ago
You can do multiple lines, just not multiple statements:
>>> f = lambda x: x * \
... 20
>>>
>>> f
<function <lambda> at 0x7f8b69f2c6a8>
>>> f(2)
40
- deleted 6y ago[deleted]
- pansa2 6y agoIn fact, no statements at all - just a single expression.
- Iwan-Zotow 6y agowell, you could pack a lot of other expressions into that expression, especially with 3.8/3.9, e.g. x,y = 1,2 q = list(map(lambda t: (tx := t*x, ty := t*y, tx+ty)[-1], [1, 2, 3]))
- pansa2 6y agoWalrus operator: not even once.
- Iwan-Zotow 6y agowalrus, actually, being an expression, it's a perfect fit for lambdas