A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2018-April/152850.html below:

[Python-Dev] PEP 572: Assignment Expressions

[Python-Dev] PEP 572: Assignment Expressions [Python-Dev] PEP 572: Assignment ExpressionsMatthew Woodcraft matthew at woodcraft.me.uk
Sat Apr 21 13:47:13 EDT 2018
On 2018-04-17 08:46, Chris Angelico wrote:
> Having survived four rounds in the boxing ring at python-ideas, PEP
> 572 is now ready to enter the arena of python-dev.

I would like to suggest one more motivating example for "Capturing
condition values": multiple regex matches with 'elif'.

if match := re.search(pat1, text):
    print("Found one:", match.group(0))
elif match := re.search(pat2, text):
    print("Found two:", match.group(0))
elif match := re.search(pat3, text):
    print("Found three:", match.group(0))

Without assignment expressions, you have an annoying choice between a
cascade of 'else's with an ever-increasing indent and evaluating all the
matches up front (so doing unnecessary work).

-M-

More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4