osdir.com

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

PEP 572 -- Assignment Expressions


On Wed, Nov 28, 2018 at 4:38 AM Ivo Shipkaliev <ivo.shipkaliev at gmail.com> wrote:
>
>    Hello.
>    Maybe it's too late for a discussion, but I just couldn't resist.
>    I just found out about this new ":=" operator. I need to ask:
>
>    What is the need for this additional ":" to the "="?
>    Why:
>          if (match := pattern.search(data)) is not None:
>                # Do something with match
>
>    What is wrong with:
>          if match = pattern.search(data) is not None:
>                # Do something with match
>
>    Assignment expression or assignment statement, it's an assignment,
> right? It is very clear to everyone that it's an assignment! Can't it all
> just be a "="?
>    Thank you very much!

It's a bug magnet.

https://www.python.org/dev/peps/pep-0572/#why-not-just-turn-existing-assignment-into-an-expression

ChrisA