Check the current Python version using a Python program

Hey coder! under this article, we are going to check the current Python version using a Python program. We are going to implement the code in just 2 lines, which seems interesting.

There are two methods for checking the current version using Python, let us discuss one by one:

Method-1: For checking the current version of Python

In method-1, we need to import the sys module.

 Importing and Implementation of code

First of all, we need to import a module named sys which is useful for checking the current version of Python.

import sys

Now, by importing the sys module, we can access all the functions and variables present in it.

At last, this is the time to find out the current version of Python.

print(sys.version)

By using the above print statement we can get the current version of Python.

Output for method -1

3.8.10 (default, Jun 2 2021, 10:49:15)
[GCC 9.4.0]

As a result, the current Python version is 3.8.10, and ( Jun 2, 2021, 10:49:15 ) tells us about, the date and time in which the 3.8.10 version is released.

Method-2: For finding the current Python version

We need to import a module named platform where a lot of information regarding our system will be present, which includes OS info, Python version, and many more.

So let us code it out.

from platform import python_version
print(python_version())

As a result, the Output will be 3.8.10 which will be the same as method-1.

Both the methods are equally important we can use any one of these methods to check the current version of Python.

Output for method-2

3.8.10

Likewise method-1, we cannot get the released date and time of the current version in method-2, that’s a disadvantage.

Finally, we learned how to check the current version of Python using Python.
That’s for this tutorial guys.

HAPPY CODING!

Similarly, you can check the below articles on your interest:

Leave a Reply

Your email address will not be published.