Python is dynamic scriptin language which provides rich features. Python have two main version named Python version 2 and version 3. We can call them simply Python2 or Python3 . In this tutorial we will learn how yo check Python version or a script version.
Python是动态脚本语言,具有丰富的功能。 Python有两个主要版本,分别称为Python版本2和版本3。我们可以简称为Python2或Python3。 在本教程中,我们将学习如何检查Python版本或脚本版本。
默认Python版本 (Default Python Version)
Every Python installation have a default version even there is two version of Python. If we can python
command and enter to the check version.
每个Python安装都有一个默认版本,即使有两个Python版本也是如此。 如果我们可以使用python
命令并输入检查版本。
$ python

We can see from first line which is like Python 2.7.15rc1
which is simply Python2. We also get the gcc
version which compiled this Python binary.
我们从第一行可以看到,就像Python 2.7.15rc1
,它就是Python2。 我们还获得了编译该Python二进制文件的gcc
版本。
python_version()函数 (python_version() Function)
Another function to check python version is python_version()
function. But first we need to import platform module like below.
检查python版本的另一个函数是python_version()
函数。 但是首先我们需要导入如下的平台模块。
import platform
platform.python_version()

版本变量(version Variable)
We can also use version
variable which is provided by sys
module.
我们还可以使用sys
模块提供的version
变量。
import sys
sys.version

Python –版本选项(Python –version Option)
Every Python interpreter supports the --version
option in the command like below bash. We can call this option like below in order to learn default Python version.
每个Python解释器在bash中都支持命令中的--version
选项。 我们可以像下面这样调用此选项,以学习默认的Python版本。
$ python --version
OR to learn Python3 subversion
或学习Python3颠覆
$ python3 --version
OR to learn Python2 subversion
或学习Python2颠覆
$ python2 --version

列出Python解释器(Listing Python Interpreters)
As Python 2 and 3 version there are different interpreters which provides Python programming language features. We can list these interpreters as files like below. We will use following ls
command.
作为Python 2和3版本,提供了Python编程语言功能的不同解释器。 我们可以将这些解释器作为如下文件列出。 我们将使用以下ls
命令。
$ ls /usr/bin/python*
