Earlier quoted context omitted.
Multi-line lambdas are fine: Python will accept newlines in certain parts of an expression, and you can use '\' for others; e.g. f = lambda x: [ x + y for y in range(x) if y % 2 == 0 ] >>> f(5) [5, 7, 9] Lambdas which perform multiple sequential steps are fine, since we can use tuples to evaluate expressions in order; e.g. from sys import stdout g = lambda x: ( stdout.write("Given {0}\n".format(repr(x))), x.append(42…
Neat. I tried it with print(), works fine. Don't need return in a lambda. Assignment now has the walrus. Leaves raise and few other odds and ends. Do believe you've cracked it! Don't think I'll use it much, but you never know... in a pinch.
You're right that the walrus makes assignment more usable; we can also call methods like .__setitem__ to get similar effects. Unfortunately the walrus seems to suffer the same broken/ambiguous scoping as assignment statements, e.g.
>>> a = 1
>>> b = lambda: (print(a), a := 2)
>>> b()
Traceback (most recent call last):
File "", line 1, in
File "", line 1, in
UnboundLocalError: cannot access local variable 'a' where it is not associated with a value
> Don't need return in a lambda`return` is needed for early returns. Notice that my `abs` example is trying to do that with `return n` (to skip the `-1 *` operation, since `n` is non-negative in that case).
> Leaves raise and a few other odds and ends
Off the top of my head: yield, match, def, import, class, with, for, while, assert, try, except, async, await.