布尔值是如何格式化字符串在Python? [英] How are booleans formatted in Strings in Python?
本文介绍了布尔值是如何格式化字符串在Python?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道我不能做的:
%B%B%(真,假)
在Python。我猜%B
为B(oolean)。有没有这样的东西吗?
解决方案
>>>打印%R,%R%(真,假)
真假
这是不特定于布尔值 - %R
调用 __ __再版
的参数的方法。 %S
(为 STR
)也应该工作。
I see I can't do:
"%b %b" % (True, False)
in Python. I guessed %b
for b(oolean). Is there something like this?
解决方案
>>> 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.
这篇关于布尔值是如何格式化字符串在Python?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文