(test?return_true:return_false)
Sean Ross
frobozz_electric at hotmail.com
Fri Jan 24 18:14:53 EST 2003
More information about the Python-list mailing list
Fri Jan 24 18:14:53 EST 2003
- Previous message (by thread): (test?return_true:return_false)
- Next message (by thread): (test?return_true:return_false)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
"Robin Munn" <rmunn at pobox.com> wrote in message news:slrnb32738.5jj.rmunn at localhost.localdomain... [snip] > 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. Or, from the "Python Cookbook": (matches == 1 and [''] or ['es'])[0] or ('', 'es')[matches != 1] or, for plurals in particular, 's'*(matches != 1)
- Previous message (by thread): (test?return_true:return_false)
- Next message (by thread): (test?return_true:return_false)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list