Linux/Unix的系统上,一般默认的 python 版本为 2.x,我们可以将 python3.x 安装在 /usr/local/python3 目录中。
安装完成后,我们可以将路径 /usr/local/python3/bin 添加到您的 Linux/Unix 操作系统的环境变量中,这样您就可以通过 shell 终端输入下面的命令来启动 Python3 。
在Window系统下你可以通过以下命令来设置Python的环境变量,假设你的Python安装在 C:\Python34 下:
我们可以在命令提示符中输入"Python"命令来启动Python解释器:
$ python3 |
print ("Hello, Python!"); |
当键入一个多行结构时,续行是必须的。我们可以看下如下 if 语句:
>>> flag = True |
>>> if flag : |
... print("flag 条件为 True!") |
... |
flag 条件为 True! |
将如下代码拷贝至 hello.py文件中:
print ("Hello, Python!"); |
python3 hello.py |
#! /usr/bin/env python3 |
$ chmod +x hello.py |
./hello.py |