This tutorial shows you how to print the current Python version from a script. We can print out the version using three methods.

Print Python Version using sys module

During Python installation, the sys module is installed as a built-in utility, which allows you to check the version of Python. Now we use sys.version property.

It is possible to get details about the version, such as the major, minor, type of release, etc., using the sys.version_info property. As shown below, the version_info property shows detailed information about the Python version in tuple form.

So firstly, we need to import the sys module in out python script then we can print the current version of Python.

Python Code

Output


Current version of Python is 3.9.7 (default, Jul 3 2021, 16:40:50)
[GCC 9.3.0]
Version info: sys.version_info(major=3, minor=9, micro=7, releaselevel='final', serial=0)

Print Python Version using platform module

As an alternative, you can use a Python platform module to print the Python version currently installed on your computer by calling platform.python_version().

Python Code

Output

Current version of Python is 3.9.7

Print Python version as tuple (major, minor, patchlevel) of strings:

We can also print current Python version in tuple format.

Python Code

Output

('3', '9', '7')

<class 'tuple'>

Check Python version on command line

Rather than writing any script, you can type python --version from the shell/command prompt to see what version of Python is currently installed.

python --version

# Output
# 3.9.7

Hopefully you enjoyed this tutorial to identify the version of Python you have installed on your computer. To determine the most recent Python version, I always use the command line.