Python Platform – Check OS version

In this post we will be creating a Python script which will check the version of the OS (operating system) that is currently installed on the machine, to do this we will be using the ‘platform’ library which gives access to the underlying platform’s identifying data.

The snippet of Python code below uses the ‘platform’ library to check the version of the OS. The result is then print to output. Note that If the value of the operating system version can’t be determined, the library will return an empty string.

import platform

release = platform.release()

print("Release:", release)

An example of what the above would return as output can be seen below.

System: Windows

Take a look at some of our other content around the Python programming language by clicking here.

Leave a Reply