小编use*_*238的帖子

如何在python str.format中转义点

我希望能够访问带有点的字典中的密钥str.format().我怎样才能做到这一点?

例如,没有点的键的格式有效:

>>> "{hello}".format(**{ 'hello' : '2' })
'2'
Run Code Online (Sandbox Code Playgroud)

但是当密钥中有一个点时它不会出现:

>>> "{hello.world}".format(**{ 'hello.world' : '2' })
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
KeyError: 'hello'
Run Code Online (Sandbox Code Playgroud)

python string-formatting

8
推荐指数
1
解决办法
1371
查看次数

标签 统计

python ×1

string-formatting ×1