Visual Studio Code shows invalid syntax for "end" parameter in print() [duplicate]
I'm trying to run this Python program with Visual Studio Code:
# This Python program must be run with
# Python 3 as it won't work with 2.7.
# ends the output with a <space>
print("Welcome to" , end = ' ')
print("GeeksforGeeks", end = ' ')But while building I get following output and error messages in console:
$ python /home/mrrobot/Documents/Python/loop_while.py File "/home/mrrobot/Documents/Python/loop_while.py", line 5 print("Welcome to" , end = ' ') ^
SyntaxError: invalid syntaxWhat could be the problem here? How can I fix it?
11 Answer
As @Eliah Kagan pointed out, the error occurs because your VS Code is using Python 2 as the interpreter. Switch to Python 3 interpreter in your VS Code and it should work.
P.S. Free PEP style tip: Write print('something', end=' '). When giving default values to parameters, avoid spacing around the = operator.