• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

The Programming Expert

Solving All of Your Programming Headaches

  • HTML
  • JavaScript
  • jQuery
  • PHP
  • Python
  • SAS
  • Ruby
  • About
You are here: Home / Python / Python Get Operating System Information with os and platform Modules

Python Get Operating System Information with os and platform Modules

February 24, 2022 Leave a Comment

In Python, the os and platform modules have many useful functions which allow us to get operating system information easily.

import os
import platform

print(os.name)
print(platform.system())
print(platform.release())
print(platform.platform())

#Output:
nt
Windows
10
Windows-10-10.0.22000-SP0

In Python, the os and platform modules have provide us with many useful functions which allow us to get information about the operating system the code is running on.

We can get the name of the operating system dependent module imported with the os name property.

The name property returns values such as ‘posix’,’nt’,’os2′,’ce’,’java’, and ‘riscos’ where, for example, ‘nt’ is a Windows operating system.

The platform module provides us with a number of great functions which give us operating system information.

For example, the system() function gives us the operating system, the release() function gives us the version of the operating system, and the platform() function gives us a string identifying the underlying platform with as much useful information as possible.

Below is an example of how to get various pieces of operating system info with Python.

import os
import platform

print(os.name)
print(platform.system())
print(platform.release())
print(platform.platform())

#Output:
nt
Windows
10
Windows-10-10.0.22000-SP0

Hopefully this article has been useful for you to learn how to get operating system information with the Python os module.

Other Articles You'll Also Like:

  • 1.  pandas round – Round Numbers in Series or DataFrame
  • 2.  Python isprime – Function for Determining if Number is Prime
  • 3.  Get Last N Elements of List in Python
  • 4.  pandas sum – Get Sum of Series or DataFrame Columns
  • 5.  Negate Boolean in Python with not Operator
  • 6.  Run Something Every 5 Seconds in Python
  • 7.  Get Random Value from Dictionary in Python
  • 8.  Remove First and Last Character from String Using Python
  • 9.  Check if String Does Not Contain Substring in Python
  • 10.  Deque Peek and Queue Peek Functions in Python

About The Programming Expert

The Programming Expert is a compilation of a programmer’s findings in the world of software development, website creation, and automation of processes.

Programming allows us to create amazing applications which make our work more efficient, repeatable and accurate.

At the end of the day, we want to be able to just push a button and let the code do it’s magic.

You can read more about us on our about page.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

About The Programming Expert

the programming expert main image

Welcome to The Programming Expert. We are a group of US-based programming professionals who have helped companies build, maintain, and improve everything from simple websites to large-scale projects.

We built The Programming Expert to help you solve your programming problems with useful coding methods and functions in various programming languages.

Search

Learn Coding from Experts on Udemy

Looking to boost your skills and learn how to become a programming expert?

Check out the links below to view Udemy courses for learning to program in the following languages:

Copyright © 2023 · The Programming Expert · About · Privacy Policy