python字符串中包含大括号时怎么使用string的.format方法?

大括号是特殊转义字符,如果需要原始的大括号,用{ {代替{, 用}}代替}, 如下:

s = 'id=pc&offset={}&limit=20&strategy=1&ext={ {%22pool%22:[%22high%22,%22top%22],%22is_filter%22:10,%22check_type%22:true}}'
print(s.format(2))

运行结果:

id=pc&offset=2&limit=20&strategy=1&ext={%22pool%22:[%22high%22,%22top%22],%22is_filter%22:10,%22check_type%22:true}

猜你喜欢

转载自blog.csdn.net/Kwoky/article/details/109316414