4 ms·
The key changes seem to be [PEP-572], a bunch of small backward-compatible syntax changes, a bunch of AST (internal) changes, and bugfixes (of course). # You
by nine_k 8y ago
The key changes seem to be [PEP-572], a bunch of small backward-compatible syntax changes, a bunch of AST (internal) changes, and bugfixes (of course).
# You can now write
if (match := pattern.search(data)) is not None:
# Do something with match
# or even
[y for x in data if (y := f(x)) is not None]
This is what I personally very much anticipated.
Also nice:
# This is now supported.
x: Tuple[int, int] = 1, 2 # No parens.
yield 1, 2, 3, *rest # No parens again.
[PEP-572]: https://www.python.org/dev/peps/pep-0572/ https://www.python.org/dev/peps/pep-0572/
- mikepurvis 8y agoThat list comprehension is the most compelling case I've seen for this functionality; far more so than the basic assignment + if.
- nine_k 8y agoYes, sometimes, writing a comprehension, I was dearly missing the `let` / `where`, as seen in e.g. Haskell, or lisps.