<分区>
我的问题归结为:
# examplecode
# i want to achieve the string "1.1%"
s = '%s%' % '1.1'
# but this throws me a
ValueError: incomplete format
ofc 我可以只使用 format()
s = '{}%'.format('1.1')
但是有没有办法在 %s
之后使用 %
?
<分区>
我的问题归结为:
# examplecode
# i want to achieve the string "1.1%"
s = '%s%' % '1.1'
# but this throws me a
ValueError: incomplete format
ofc 我可以只使用 format()
s = '{}%'.format('1.1')
但是有没有办法在 %s
之后使用 %
?
最佳答案
用另一个%
转义%
,像这样
>>> s = '%s%%' % '1.1'
>>> s
'1.1%'
关于python - 如何在 python 中的 %s 之后使用 %?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29254854/