Why are py and python giving different results?

Viewed 324

Using py and are giving me different results in the Command Prompt. For my specific program, when I run python file.py, the program works as expected. However, when I run py file.py, it gives me this error:

  File "wordcount.py", line 60
print(f"{wordlist[num]} {wordcount[num]}")
                                        ^

SyntaxError: invalid syntax

Can anyone tell me why works and not py?

EDIT: I should clarify, I've already checked the system. Typing py gives me Python 3.8.3, which means that the 2.x explanation doesn't match my case. import sys going into print(sys.version) gives me the same results.

2 Answers

Probably py is set to Python 2 and python is set to Python 3 on your system.

Try checking the versions with python --version and py --version respectively.

It's not working with Python 2 since your code uses f-Strings, which where added in Python 3.6.

it is because you are having two versions of python installed on your computer when you run py [file.py] it runs on python 2.x version when you run python [file.py] it runs on python 3.x version.
You are using f-string's it is latest feature of the python so it won't run on python 2.x verison

just try checking version by typing py --verion and python --version

Related