python - 我使用 format() 内置函数时出现的错误消息

标签 python python-3.x built-in

这是我的代码和错误消息:

>>> message = ‘The price of this {0:s} laptop I {1:d} USD and the exchange rate is {2:4.2f} USD to 1 EUR’.format(‘Apple’, 1299, 1.23342342)
SyntaxError: invalid character in identifier

根据我正在关注的书,我的代码是正确的。我应该提到的是,单词“The”以粉红色突出显示,单词“and”“is”均显示为黄色。

最佳答案

您使用了错误的引号字符,您需要使用 '"

message = 'The price of this {0:s} laptop I {1:d} USD and the exchange rate is {2:4.2f} USD to 1 EUR'.format('Apple', 1299, 1.23342342)

关于python - 我使用 format() 内置函数时出现的错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43600652/

相关文章:

python - 使用 scipy 从 delaunay 三角剖分输出顶点

python-3.x - for循环消除偶数

python 象形文字

python - 内置的 object() 什么时候有用?

python - itertools.ifilter 对比过滤器对比列表推导

python - 两个numpy ndarrays的字典序比较

python - 使用一维列索引数组切片并填充二维数组

python - psycopg2.connect 失败,错误为 'connection refused'(Django app+db 托管在单独的虚拟机上)

python - 使用 pip install 安装 ssl 时遇到问题 : "SyntaxError: Missing parentheses in call to ' print'"

Python:如果键不在字典中,为什么不调用 __eq__() ?