Why ELIF?

TerryP bigboss1964 at gmail.com
Sun Oct 11 10:45:43 EDT 2009


On Oct 11, 7:07 am, Erik Max Francis <m... at alcyone.com> wrote:
> Because that's uglier.  `or` means something completely unrelated in
> expressions.  Variations of `else if` in `if ... else if ...` chains is
> routine in computer languages.  Choosing a deliberately different syntax
> just for the sake it of is obtuse at best.
>

I agree - first thing I do when learning a language, is find out what
the local brew is, e.g.: if (expr) {block} else if (expr) {block} else
{block}. It is just a part of programming. Which style it uses, is
mostly inconsequential, as long as the language documents the syntax
and behaviour, all is good [sic].

On Oct 11, 8:07 am, Steven D'Aprano <st... at REMOVE-THIS-
cybersource.com.au> wrote:
> By the way, if you're testing a single name against a series of
> alternatives, it is often better to look up the value in a dictionary:
>
> table = {bar: 23, baz: 42, boop: 73, beep: 124}
> value = table[foo]
>
> instead of:
>
> if foo == bar:
>     value = 23
> elif foo == baz:
>     value = 42
> elif ...
>

my personally favorite is: foo in table, when applicable.



More information about the Python-list mailing list