DEV Community

Srinivas Ramakrishna for ItsMyCode

Posted on • Originally published at itsmycode.com on

2 1

How to Check and Print Python Version?

ItsMyCode |

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

Print Python Version using sys Module

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)
Enter fullscreen mode Exit fullscreen mode

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)]
Enter fullscreen mode Exit fullscreen mode

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)
Enter fullscreen mode Exit fullscreen mode

Output

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

Print Python Version using platform Module

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())
Enter fullscreen mode Exit fullscreen mode

Output

Current version of Python is 3.9.7
Enter fullscreen mode Exit fullscreen mode

Print Python version using command line

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

python --version

# Output 
# 3.9.7
Enter fullscreen mode Exit fullscreen mode

The post How to Check and Print Python Version? appeared first on ItsMyCode.

Image of Quadratic

Python + AI + Spreadsheet

Chat with your data and get insights in seconds with the all-in-one spreadsheet that connects to your data, supports code natively, and has built-in AI.

Try Quadratic free

Oldest comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Engage with a wealth of insights in this thoughtful article, cherished by the supportive DEV Community. Coders of every background are encouraged to bring their perspectives and bolster our collective wisdom.

A sincere “thank you” often brightens someone’s day—share yours in the comments below!

On DEV, the act of sharing knowledge eases our journey and forges stronger community ties. Found value in this? A quick thank-you to the author can make a world of difference.

Okay