How to Check and Print Python Version?

In this tutorial, you will learn how to print the version of the current Python installation from the script.

The sys module comes as a built-in utility with Python installation, and to check the Python version, use sys.version property.

import sys

# Prints current Python version
print("Current version of Python is ", sys.version)

Output

Current version of Python is  3.9.7 (tags/v3.9.7:1016ef3, Aug 30 2021, 20:19:38) [MSC v.1929 64 bit (AMD64)]

If you are looking for details on the version, such as major, minor, type of release, etc., you can use sys.version_info property.

The version_info property prints the Python version in tuple format, which gives detailed information as shown below.

import sys

# Prints current Python version
print("Current version of Python is ", sys.version_info)

Output

Current version of Python is  sys.version_info(major=3, minor=9, micro=7, releaselevel='final', serial=0)

The other alternative way is to use a platform module in Python where you can leverage the built-in function platform.python_version()  to print the current installed Python version in your machine.

import platform

# Prints current Python version
print("Current version of Python is ", platform.python_version())

Output

Current version of Python is  3.9.7

If you don’t want to write any script but still want to check the current installed version of Python, then navigate to shell/command prompt and type python --version

python --version

# Output 
# 3.9.7
Leave a Reply

Your email address will not be published. Required fields are marked *

Sign Up for Our Newsletters

Subscribe to get notified of the latest articles. We will never spam you. Be a part of our ever-growing community.

You May Also Like