在使用dict时获取密钥错误模板.格式()

2024-04-25 04:27:57 发布

您现在位置:Python中文网/ 问答频道 /正文

在这件事上不知所措。我得到了一个键错误,但我不明白为什么引用的键看起来像是在dict中

有什么帮助吗?在

TEMPLATE = "{ticker:6s}:{shares:3d} x {price:8.2f} = {value:8.2f}"

report = []

stock = {'ticker': 'AAPL', 'price': 128.75, 'value': 2575.0, 'shares': 20}

report.append(TEMPLATE.format(stock))

这是我得到的错误:

^{pr2}$

Tags: reportformatvalue错误stocktemplatepricedict