Why ELIF?

MRAB python at mrabarnett.plus.com
Sun Oct 11 17:50:50 CEST 2009


Grant Edwards wrote:
> On 2009-10-11, metal <metal29a at gmail.com> wrote:
> 
>> I wonder the reason for ELIF. it's not aligned with IF, make code ugly
> 
> It most certainly is aligned with IF:
> 
> 
>   if cond1:
>       do this
>   elif cond2:
>       do that
>   else:
>       do the other
> 
> The "if" "elif" and "else" are all aligned in all of the code
> I've ever seen.
> 
In some other languages, eg Modula-2, it's 'elsif'; the disadvantage
there is that if you were hearing it read out you might ask:

     Do you mean 'elsif' or 'else if'?

so 'elif' is not only shorter, it's clearer.



More information about the Python-list mailing list