[Python-Dev] PEP 572: Assignment Expressions (original) (raw)
Sven R. Kunze srkunze at mail.de
Mon Apr 23 17:34:22 EDT 2018
- Previous message (by thread): [Python-Dev] PEP 572: Assignment Expressions
- Next message (by thread): [Python-Dev] PEP 572: Assignment Expressions
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 23.04.2018 23:19, Barry Warsaw wrote:
I also think it effectively solves the switch-statement problem:
if (getresponse() as answer) == 'yes': doit() elif answer == 'no': skipit() elif answer == 'maybe' okaythen() That’s Pythonic enough for jazz!
Is it just me or since when has the following Python code fallen out of favor?
answer = get_response() if answer == 'yes': do_it() elif answer == 'no': skip_it() elif answer == 'maybe' okay_then()
I really don't see anything I would want to optimize here. Not even a single bit. But as said that might just be me.
What I like about this code is:
- symmetry: all ifs are equally structured
- classic IPO model: first get input, then process (, then output)
Sven
- Previous message (by thread): [Python-Dev] PEP 572: Assignment Expressions
- Next message (by thread): [Python-Dev] PEP 572: Assignment Expressions
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]