如何有选择地在Python字符串中转义百分比(%)?我有以下代码test = "have it break."selectiveEscape = "Print percent % in sentence and not %s" % testprint(selectiveEscape)我想获得输出:Print percent % in sentence and not have it break.实际发生了什么: selectiveEscape = "Use percent % in sentence and not %s" % testTypeError: %d format: a number is required, not str
3 回答
陪伴而非守候
TA贡献1757条经验 获得超8个赞
>>> test = "have it break."
>>> selectiveEscape = "Print percent %% in sentence and not %s" % test
>>> print selectiveEscape
Print percent % in sentence and not have it break.
添加回答
举报
0/150
提交
取消