【发布时间】:2015-03-25 19:56:29
【问题描述】:
我的问题归结为:
# examplecode
# i want to achieve the string "1.1%"
s = '%s%' % '1.1'
# but this throws me a
ValueError: incomplete format
我可以使用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
我可以使用format()
s = '{}%'.format('1.1')
但是有没有办法在%s 之后使用% ?
【问题讨论】:
用另一个% 转义%,像这样
>>> s = '%s%%' % '1.1'
>>> s
'1.1%'
【讨论】:
你可以把 % 翻倍。
s = '%s%%' % '1.1'
【讨论】:
加倍 %,"%s%%" % 10 应该给你10%。
【讨论】: