(test?return_true:return_false)

Robin Munn rmunn at pobox.com
Fri Jan 24 17:56:43 CET 2003


Erik Max Francis <max at alcyone.com> wrote:
> Daniel wrote:
> 
>> Oh no, I've become one of THEM!  Thank you, the a and b or c is good
>> enough for me.
> 
> Just remember that a and b or c won't work if b is false.

So for the example you quoted:

    print 'Search complete (%d match%s found)'%(matches,(matches==1?'':'es'))

the "a and b or c" trick won't work, since an empty string is considered
false. You would need to invert the test. Instead of:

    (matches==1) and '' or 'es'

use:

    (matches!=1) and 'es' or ''

This will work properly.

-- 
Robin Munn <rmunn at pobox.com>
http://www.rmunn.com/
PGP key ID: 0x6AFB6838    50FF 2478 CFFB 081A 8338  54F7 845D ACFD 6AFB 6838




More information about the Python-list mailing list