On 09/11/2013 22:44, Jonathan wrote:
On Saturday, November 9, 2013 8:27:02 AM UTC-5, Joshua Landau wrote:

`select` is quite an odd statement, in that in most cases it's just a
weaker variant of `if`. By the time you're at the point where a
`select` is actually more readable you're also at the point where a
different control flow is probably a better idea. Things like
dictionaries or a variables pointing to functions are really useful
and can be encapsulated in a class quite well. This is a bit more
advanced but largely more rigorous.

But most of the time the idea is just that an `if` is more explicit,
and it's not like a `case` statement can be optimised as it can in
lower-level languages with simpler datatypes.

The C switch statement is very limited.  The select statement in the dialect of BASIC I regularly 
use is more flexible.   It's more concise on long if chains because it elides the "end 
if"s.  But the use of indentation for blocks and the "in" operator certainly reduce 
the need for it in Python.

In pythonic syntax:

select <expression0>:
   case <case expression>,[<case expression>],:
   ....
   ....
   case else:

[snip]

It's more likely that the cases would be indented the same amount as
the 'select', and you wouldn't need 'case else', just 'else'.

--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to