Hi, in this blog lets learn how to Write a Python Program to Get The Python Version You Are Using.
In the command prompt you can easily find the python version, just type python --version and it will display the python version you are using.
C:\Users\Public>python --version
Python 3.8.5
C:\Users\Public>
Now there are two methods to get the Python Version during run time first is using Python Sys Module and Next is platform Module. Lets look into both Methods.
Python Version using Python Sys Module
In the below program use sys.version and sys.version_info variables to get the python version info. Its a type of tuple, you need to convert it into string using type conversion str() function.
import sys
print("Python Version : "+ str(sys.version))
print("Version Info : " + str(sys.version_info))
print("Release : " + str(sys.version_info[0]) + "." + str(sys.version_info[1]))
OUTPUT :
Python Version : 3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:57:54) [MSC v.1924 64 bit (AMD64)]
Version Info : sys.version_info(major=3, minor=8, micro=5, releaselevel='final', serial=0)
Release : 3.8
Python Version using Python Platform Module
In the below program just use platform library and use platform.python_version() function it will return a string containing python version. Just print the string using print() function call.
import platform
print("The Python version you are currently using is ...")
print(platform.python_version())
OUTPUT :
The Python version you are currently using is ...
3.8.5
Conclusion : Got any query / suggestion to improve this blog, comment down below.
0 Comments