[Python-Dev] PEP 572: Assignment Expressions

Barry Warsaw barry at python.org
Mon Apr 23 17:19:36 EDT 2018


On Apr 23, 2018, at 13:01, Ethan Furman <ethan at stoneleaf.us> wrote:
> 
> On 04/22/2018 10:44 PM, Tim Peters wrote:
>> 
>> 
>> I find myself warming more to binding expressions the more I keep them
>> in mind while writing new code.

And I really like the term “binding expressions” because that’s how I think about this feature. I also think it will be easier to explain because “all it does” is bind a value to a name, and to me that’s the most powerful and valuable thing behind this feature.

> So I really like being able to make the assignment in the expression, but I have a really hard time parsing it with the name first.

Me too.  Plus we *already* have precedence for spelling name bindings in similar constructs, such as import statements, with statements, and exceptions.  It seems like a natural and Pythonic approach to extend that same spelling to binding expressions rather than introducing new, weird, symbols.

I also think it effectively solves the switch-statement problem:

if (get_response() as answer) == 'yes':
    do_it()
elif answer == 'no':
    skip_it()
elif answer == 'maybe'
    okay_then()

That’s Pythonic enough for jazz!

-Barry

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: Message signed with OpenPGP
URL: <http://mail.python.org/pipermail/python-dev/attachments/20180423/539adbf1/attachment.sig>


More information about the Python-Dev mailing list