Terry Reedy tjreedy at
Thu Aug 7 19:36:45 CEST 2003

"Martin v. Löwis" <martin at> wrote in message
news:m34r0tmmcm.fsf at
> 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