python - Python中的字符串如何格式化 boolean 值?

标签 python boolean string-formatting

我知道我做不到:

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

在 Python 中。我猜 %b 是 b(oolean)。有这样的吗?

最佳答案

>>> print "%r, %r" % (True, False)
True, False

这并不特定于 boolean 值 - %r 调用参数的 __repr__ 方法。 %s(对于 str)也应该可以工作。

关于python - Python中的字符串如何格式化 boolean 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2259228/

相关文章:

python - 格式化字符串时不理解 "IndexError: tuple index out of range"的原因

Python Selenium 未加载整页源代码

java - SharedPreferences:为什么我的值没有被覆盖?

c++ - 在 C++ 中使用 boolean 数组减少错误

c++ - 在 Interfaces.C 中传递 boolean Ada 类型

printf() 能否为值 (-0.5) 生成 "-.5"?

python - 如何使用变量作为列表索引?

python - python 的尾部。最佳性能实现

python - 方法对象在神经网络代码中不可下标

vb.net - 根据给定的出生日期计算年龄