小编laz*_*zis的帖子

为什么在Python 3.6中评估f"\ {10}"时符号"{"仍然存在?

f-string是Python 3.6中的新功能之一.

但是,当我尝试这个:

>>> f"\{10}"
'\\{10'
Run Code Online (Sandbox Code Playgroud)

我无法弄清楚为什么左大括号'{'保留在结果中.我认为结果应该与str.format:

>>> "\{}".format(10)
'\\10'
Run Code Online (Sandbox Code Playgroud)

PEP-0498中,它没有明确回答这个问题.那么是什么原因导致左大括号'{'留在结果和是什么原因导致之间的差异f-stringstr.format()

python python-3.x python-3.6 f-string

13
推荐指数
1
解决办法
390
查看次数

标签 统计

f-string ×1

python ×1

python-3.6 ×1

python-3.x ×1