How To Check Python Version? – POFTUT

How To Check Python Version?


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.

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
Default Python Version
Default Python Version

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_version() Function

Another function to check python version is python_version() function. But first we need to import platform module like below.

import platform  
platform.python_version()
python_version() Function
python_version() Function

version Variable

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

import sys    
sys.version
version Variable
version Variable

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 --version

OR to learn Python3 subversion

$ python3 --version

OR to learn Python2 subversion

$ python2 --version
--version Option
–version Option

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.

$ ls /usr/bin/python*
Listing Python Interpreters
Listing Python Interpreters

LEARN MORE  How to Install Pip in Debian, Ubuntu, Kali, Mint?

Leave a Comment