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