在 Ubuntu 上安装 Python 后,可以通过以下步骤进行测试:
打开终端(快捷键:Ctrl + Alt + T)
输入 python --version
或 python3 --version
,然后按回车键。这将显示已安装的 Python 版本。例如:
Python 3.8.5
或者
Python 2.7.18
请注意,Ubuntu 20.04 及更高版本默认安装的是 Python 3。如果你想测试 Python 2,可以使用 python2
命令。
python
或 python3
(取决于你要测试的版本),然后按回车键。这将打开一个交互式环境,你可以在其中输入 Python 代码并立即查看结果。例如:$ python3
Python 3.8.5 (default, Jul 28 2020, 12:59:40)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> print("Hello, World!")
Hello, World!
>>> exit()
按 Ctrl + D
退出 Python 交互式解释器。
.py
文件,例如 test.py
。然后在终端中使用 python
或 python3
命令运行脚本。例如:$ python3 test.py
这将执行 test.py
文件中的 Python 代码,并显示输出结果。
通过以上步骤,你可以测试 Ubuntu 上安装的 Python 是否正常工作。