How are booleans formatted in Strings in Python?

后端 未结 4 1311
执念已碎
执念已碎 2021-01-30 06:13

I see I can\'t do:

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

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

4条回答
  •  伪装坚强ぢ
    2021-01-30 06:19

    >>> 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.

提交回复
热议问题