[英]Same function is giving different results in opposite order in Python. Why?
[英]Why are py and python giving different results?
使用 py 和python在命令提示符中给了我不同的结果。 对于我的特定程序,当我运行python file.py
时,程序按预期工作。 但是,当我运行py file.py
时,它给了我这个错误:
File "wordcount.py", line 60
print(f"{wordlist[num]} {wordcount[num]}")
^
SyntaxError: invalid syntax
谁能告诉我为什么python有效而不是 py?
编辑:我应该澄清一下,我已经检查了系统。 键入 py 给我 Python 3.8.3,这意味着 2.x 的解释与我的情况不符。 import sys 进入 print(sys.version) 给了我相同的结果。
可能py
在您的系统上设置为 Python 2 和python
设置为 Python 3 。
尝试分别使用python --version
和py --version
检查版本。
它不适用于 Python 2,因为您的代码使用了 f-Strings,它是在 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.
您正在使用 f-string,它是 python 的最新功能,因此它不会在 python 2.x 版本上运行
只需尝试通过键入 py --verion 和 python --version 检查版本
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.