How are booleans formatted in Strings in Python?

后端 未结 4 1316
执念已碎
执念已碎 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:20

    If you want True False use:

    "%s %s" % (True, False)
    

    because str(True) is 'True' and str(False) is 'False'.

    or if you want 1 0 use:

    "%i %i" % (True, False)
    

    because int(True) is 1 and int(False) is 0.

提交回复
热议问题