为什么我从f-string中得到了"无效的语法"的错误提示?

12 浏览
0 Comments

为什么我从f-string中得到了"无效的语法"的错误提示?

我在Python 3中无法使用f-strings。我在REPL中尝试了以下代码:

In [1]: state = "Washington"
In [2]: state
Out[2]: 'Washington'
In [3]: my_message = f"I live in {state}"
File "", line 1
my_message = f"I live in {state}"
                                ^
SyntaxError: invalid syntax

我以为我的机器默认使用的是Python 2,但是快速检查后发现:

Python 3.5.2 (default, Nov 17 2016, 17:05:23) 
Type "copyright", "credits" or "license" for more information.
IPython 5.2.2 -- An enhanced Interactive Python.

出了什么问题,我该如何解决?

0