Coding style and else statements

sjdevnull at yahoo.com sjdevnull at yahoo.com
Wed Aug 30 13:26:31 EDT 2006


Tal Einat wrote:
> I meant to say that:
>
> (thing and [thing+1] or [-1])[0]
>
> is more readable (IMO) than:
>
> thing != -1 and (thing and thing+1 or -1) or 0

Neither is particularly readable, though I agree that the latter is
worse since it has to have the third option ("0") on the end.  But I'd
go with an if statement unless I had a real reason to use something so
unreadable.  If you are enamored of such constructs, 2.5 will allow
conditional expressions:

(thing + 1) if thing else -1




More information about the Python-list mailing list