我必须用列表中的变量替换某些占位符,但是我不确定如何重新格式化占位符。warning = 'I don\'t recognize the name {0}. Did you mean {1}?'上面的代码行是我需要重新格式化的。任何帮助将不胜感激。
1 回答
慕桂英3389331
TA贡献2036条经验 获得超8个赞
这是默认的 Python 格式字符串,它可以与format.
>>> warning = 'I don\'t recognize the name {0}. Did you mean {1}?'
>>> warning.format("Meliodus123", "format")
"I don't recognize the name Meliodus123. Did you mean format?"
中的数字{0}表示传递给 的参数位置format。
添加回答
举报
0/150
提交
取消
