Reuven M. Lerner @lernerpython.com · 18d

Old #Python: n = len(data); if n > 10: ... New Python: if (n := len(data)) > 10: ... The walrus operator (3.8) assigns and tests in one expression — handy in "if" and "while" conditions, and in comprehensions.

5 likes 1 replies

?

Replies

bjkeefe · 18d

I usually find the walrus operator not worth the loss of clarity (ZoP #2) but that's a good example: worth the slight loss of clarity for the gain in succinctness.