如何在python中对字符串进行格式化 [重复]。

问题描述 投票:0回答:1

我只是不能对一个字符串的格式。

id = "3123123"
a = '{"classes": [], "field": {}}'.format(id)
print(a)

enter image description here

所有的建议都是好的!

python
1个回答
3
投票

你的格式化字符串与 格式化占位符指定器

你需要逃离 {{{

a = '{{"classes": [], "field": {{}}}}'.format(id)

并确保有一个占位符为 id 在格式化字符串中加入 {}

© www.soinside.com 2019 - 2024. All rights reserved.