这是我的代码和错误消息:
>>> 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/