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

Oleg Broytman phd at phdru.name
Thu Apr 17 23:53:43 CEST 2014


While I don't think it's a good addition for Python...

On Thu, Apr 17, 2014 at 02:41:56PM -0700, Andrew Barnert <abarnert at yahoo.com.dmarc.invalid> wrote:
> On Apr 17, 2014, at 12:14, "Lucas Malor" <7vsfeu4pxg at snkmail.com> wrote:
> 
> > switch_stmt ::=  "switch" switch_expr "case" case_expr ":" suite
> >    ("case" | "elcase" case_expr ":" suite)*
> >    ["else" ":" suite]
> > switch_expr ::= expression
> > case_expr ::= expression_list
> 
> > - if case_expr is a tuple, the case suite will be executed if switch_expr is a member of the tuple
> 
> So there's no way to switch on a tuple?

   A tuple can be a member of a bigger tuple:

>>> (1, 'b') in ((1, 'a'), (1, 'b'), (1, 'a', 'b'))
True

Oleg.
-- 
     Oleg Broytman            http://phdru.name/            phd at phdru.name
           Programmers don't die, they just GOSUB without RETURN.


More information about the Python-ideas mailing list