如何检查Python版本?

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
Default Python Version
Default Python Version
默认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()
python_version() Function
python_version() Function
python_version()函数

版本变量(version Variable)

We can also use version variable which is provided by sys module.

我们还可以使用sys模块提供的version变量。

import sys    
sys.version
version Variable
version Variable
版本变量

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
--version Option
–version Option
–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*
Listing Python Interpreters
Listing Python Interpreters
列出Python解释器
LEARN MORE  How To Install Python (Python2 and Python3) On Windows?
了解更多信息如何在Windows上安装Python(Python2和Python3)?

翻译自: https://www.poftut.com/how-to-check-python-version/

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值