1

I am getting a syntax error only in VSC not in PyCharm.

user = "Hey"
a = f"Hello World {user}"

print(a)

Exception:

File "/var/folders/4p/bxqjj1910_vd05mk0cywnrxr0000gn/T/tempCodeRunnerFile.python", line 2
a = f"Hello World {user}"
^
SyntaxError: invalid syntax

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
J R
  • 11
  • 2
  • What's your Python version in VS? – Austin Jul 13 '19 at 17:11
  • 1
    May be you were using different python version among the IDEs. f-strings are available only from python 3.6 onwards. – Abdul Niyas P M Jul 13 '19 at 17:11
  • you are running a python version which is below python 3.6 version. Isn't it? – Kushan Gunasekera Jul 13 '19 at 17:12
  • Using 3.7.4, should be the same version on both! – J R Jul 13 '19 at 17:13
  • That code works find in my VS code with Python 3.7.3. – Rory Daulton Jul 13 '19 at 17:13
  • check this [answer](https://stackoverflow.com/a/41588204/6194097) and try this in both IDEs. Then check the versions and update this question accordingly. – Kushan Gunasekera Jul 13 '19 at 17:16
  • 1
    @KushanGunasekera wow ur right, on he bottom left is 3.74, but your statement prints 2.7.10. Sorry I am just a beginner, thought i had the version displayed on the bottom left. How do i properly update in VSC? – J R Jul 13 '19 at 17:19
  • check this [How can I change python version in Visual Studio Code?](https://stackoverflow.com/q/48135624/6194097) or [Using Python environments in VS Code](https://code.visualstudio.com/docs/python/environments) – Kushan Gunasekera Jul 13 '19 at 17:25

1 Answers1

-1

I think you have an old version in python. This f-string is available in Python 3.6 or later. Goto this link and upgrade your python version. And set the path to Environmental variables.

https://www.python.org/downloads/

Sachin Muthumala
  • 775
  • 1
  • 9
  • 17