安装 Python
打印第一句 hello
这篇教程适用于 Debian 和 Ubuntu。打开终端,安装 Python 3,再写一个只有一行的程序。
安装 Python 3
先运行 python3 --version。如果终端显示 Python 3 的版本号,就可以直接写代码。如果提示找不到命令,运行下面几行。用 root 登录时,去掉 sudo。
sudo apt update
sudo apt install python3
python3 --version
新建 hello.py
用文本编辑器新建一个名为 hello.py 的文件,写入下面这行并保存。
print("hello")
运行程序
在终端进入 hello.py 所在的目录,执行下面的命令。
python3 hello.py
终端会输出这一行。
hello