[Python-ideas] Yet Another Switch-Case Syntax Proposal

Bruce Leban bruce at leapyear.org
Tue Apr 22 18:59:10 CEST 2014


On Apr 22, 2014 8:28 AM, "Lucas Malor" <7vsfeu4pxg at snkmail.com> wrote:
>
> Sorry, I didn't read it carefully. Anyway, youe example can be written as:
>
>> for i in range(5):
>>     print(i, end=' => ')
>>     if i == 1:
>>         print('one')
>>     elif i == (2,3):
>>         print('tuple(two, three)')
>>     elif i in (2, 3):
>>         print('two or three')
>>     elif i > 3:
>>         print('more than three')
>>     else:
>>         print('unmatched')
>
> and it's much simpler to read. I suggested the switch statement for a
simpler alternative to the if-elif chain.

<sigh> My code can be written as a series of static print statements too
and that would be even easier to read. It's an *example* to illustrate use
not actual useful code!

My point is that this Case class does what you want with no language
changes. And looking at your sample above exactly how would your new switch
statement be better than either my code or your if/elif chain?

--- Bruce
(from my phone)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140422/90a9da15/attachment.html>


More information about the Python-ideas mailing list