Using py and python 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 python 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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With