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.

Sign Up for Our Newsletters

Get notified of the best deals on our WordPress themes.

You May Also Like
Javascript

Javascript URLEncode

Let us take a look at what would be the best approach for Encoding URL using Javascript. There are basically 3 Javascript URLEncode methods available. Types of Javascript URLEncode escape()…
View Post
Node.js

Node.js Environment Setup

Table of Contents Hide NodeJS Installation Video TutorialInstalling Node.js and npm on Windows Operating SystemInstalling Node.js and npm on MacInstalling Node.js using XCode and HomebrewInstall Node.js on Ubuntu It’s very…
View Post
Python String Lower()

Python String lower()

Table of Contents Hide lower() Syntax lower() Parameterslower() Return ValueExample 1: Convert a string to lowercaseExample 2: String with Alphanumeric charactersExample 3: How to check if two strings are same…
View Post