问题
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