Python Platform – Check operating system

In this post we will be creating a Python script that will check which operating system is being run on the local machine, to do this we will be using the ‘platform’ library which gives access to the underlying platform’s identifying data.

The following Python code sample uses the ‘platform’ library to check the operating system in use. The result is then print to output. Note that If the operating system can’t be determined, the library will return an empty string.

import platform

system = platform.system()

print("System:", system)

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