True

Terry Reedy tjreedy at udel.edu
Thu Aug 7 13:36:45 EDT 2003


"Martin v. Löwis" <martin at v.loewis.de> wrote in message
news:m34r0tmmcm.fsf at mira.informatik.hu-berlin.de...
> If you prefer compactness, use
>
> def boolean2str(val, results=('1', '0')):
>      return results[not val]

-or, more safely (no default arg to accidently overwrite)-

def boolean2str(val):
    return val and '1' or '0'

But one might want the flexibility of intentionally replacing the
results default, as in

print boolean2str(somevalue, ('T', 'F'))

Terry J. Reedy








More information about the Python-list mailing list