How are booleans formatted in Strings in Python?

Juanjo Conti picture Juanjo Conti · Feb 13, 2010 · Viewed 166.4k times · Source

I see I can't do:

"%b %b" % (True, False)

in Python. I guessed %b for b(oolean). Is there something like this?

Answer

danben picture danben · Feb 13, 2010
>>> print "%r, %r" % (True, False)
True, False

This is not specific to boolean values - %r calls the __repr__ method on the argument. %s (for str) should also work.