0

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?

Karl Knechtel
  • 62,466
  • 11
  • 102
  • 153
  • Your script works correctly for me under python3.6 -- how are you invoking this file? – anthony sottile Sep 18 '17 at 01:55
  • 1
    The stacktrace you are getting is identical to the one shown for python2 / python3<3.6 – anthony sottile Sep 18 '17 at 01:57
  • 2
    **Do not ever remove** any version of Python that comes with your computer. **You can seriously damage your operating system**, which may depend on that Python in any number of ways that are not documented and can't easily be checked. – Karl Knechtel Jan 22 '23 at 02:54

1 Answers1

1

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

python --version

subjord
  • 109
  • 1
  • 10