Inline Conditionals?

Antoon Pardon apardon at
Thu Aug 26 15:55:59 CEST 2004

Op 2004-08-26, Alex Martelli schreef <aleaxit at>:
> Peter Hansen <peter at> wrote:
>> Joshua Ginsberg wrote:
>> > Is there any plan to include inline conditionals in Python? For example:
>> > 
>> > def isNegative(x):
>> >     return x < 0 ? True : False
>> This is a FAQ: 
>> Newbies, please consider reading the several FAQs that you will find
>> at before posting questions which
>> might be answered there (i.e. just about anything).
> Peter's right.  And Joshua's example shows how wise the BDFL was in
> ruling out ternaries: sure, good programmers might occasionally have
> found good uses for them, but we' have paid that with a LOT of horrid
> code like that -- I've seen lots like that in C & its ilk, too.

When using list comprehension not having a ternary operator can be
a PITA. It is of course possible I miss something but how am I
supposed to do the following:

   [ ? foo(x) : bar(x) for x in Somelist ]

Antoon Pardon

More information about the Python-list mailing list