f-string python无效的sysntax [英] f-string python invalid sysntax
问题描述
我最近尝试学习用 python 编写代码,但我对我们那里的任何编程语言的知识都为零,我在其中遇到了这个问题,我正在尝试使用 f-string 函数.
I recently trying to learn to code in python and I have zero knowledge in any programming languages our there and I encounter this problem in it, in which I am trying to use the f-string function.
我的 Python 版本是 3.6.2
My Python version is 3.6.2
这是我要运行的代码
greeting = 'Hello'
name = 'John'
message = f'{greeting} {name}. Welcome!'
print(message)
这是它向我显示的错误.
and here's the error it shows me.
File "/Users/RQ/Desktop/intro.py", line 16
message = f'{greeting} {name}. Welcome!'
^
SyntaxError: invalid syntax
[Finished in 0.0s with exit code 1]
我使用的是 Mac 10.12.6 操作系统版本
I am using Mac 10.12.6 OS version
我还删除了其中的默认 python 2.7 版本.
I also removed the default python 2.7 version in it.
我该怎么做才能修复它?
what should I do to fix it?
推荐答案
f-string 本身是正确的.尝试弄清楚实际使用的是哪个版本的python.
The f-string itself is correct. Try to figure out what version of python is actually used.
python --version
这篇关于f-string python无效的sysntax的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!