How to Check the Version of the Python Interpreter

You can use the sys library in order to check the version of your Python Interpreter:

import sys
print (sys.version) 

This is how the syntax would look like:

How to Check the Version of the Python Interpreter

In my case, the version that I’m currently using is 3.8.2:

version 3.8.2

Get the components of your version

If you want to get the components of your version, you may use:

import sys
print (sys.version_info)

For example, I got the following 5 components:

Check the Version of the Python Interpreter

Here is another way to get the components:

import sys

major = sys.version_info.major
minor = sys.version_info.minor
micro = sys.version_info.micro
releaselevel = sys.version_info.releaselevel
serial = sys.version_info.serial

print (major)
print (minor)
print (micro)
print (releaselevel)
print (serial)

As you can see, the 5 components are:

How to Check the Version of the Python Interpreter

Additional way to construct the Python version

Optionally, you can construct the version of your Python Interpreter as follows:

import sys

major = sys.version_info.major
minor = sys.version_info.minor
micro = sys.version_info.micro

python_version = str(major) + '.' + str(minor) + '.' + str(micro)
print (python_version)

As before, the Python version is 3.8.2:

Version 3.8.2