f-string python invalid sysntax

可紊 提交于 2021-02-04 21:38:56

问题


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.

My Python version is 3.6.2

and here's the code that I am trying to run

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]

I am using Mac 10.12.6 OS version

I also removed the default python 2.7 version in it.

what should I do to fix it?


回答1:


The f-string itself is correct. Try to figure out what version of python is actually used.

python --version



来源:https://stackoverflow.com/questions/45790054/f-string-python-invalid-sysntax

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!