2017-04-25 45 views
2

这里是我的代码,并且错误信息:错误信息的内置功能

>>> 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”“是”两个词都显示为黄色。

+0

看起来您正在使用错误的引号。使用''''或'''字符引用你的字符串。 – Craig

+0

谢谢,是的,你说得对! – TJE

回答

2

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

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) 
+0

当然,谢谢,我确实希望错误信息指向引号。 – TJE