我有以下代码
test = "have it break."
selectiveEscape = "Print percent % in sentence and not %s" % test
print(selectiveEscape)
我想得到输出:
Print percent % in sentence and not have it break.
实际发生的情况:
selectiveEscape = "Use percent % in sentence and not %s" % test
TypeError: %d format: a number is required, not str
或者,从Python 2.6开始,您可以使用新的字符串格式(如PEP 3101所述):
这是特别方便,因为你的字符串变得更复杂。
尝试使用
%%
打印%符号。相关问题 更多 >
编程相关推荐