← Go Back

How to Get the Running Operating System

The os.name string contains one of the following values depending on the operating system Python is running on:

  • 'nt' (Windows).
  • 'posix' (POSIX systems and Linux distributions ).
  • 'java' (when the Python implementation is Jython).

>>> import os
>>> os.name
'nt'

The platform standard module can return the name of the operating system in greater detail:

>>> import platform
>>> platform.platform()
'Windows-10-10.0.22621-SP0'

>>> import platform
>>> platform.platform()
'Linux-4.13.0-26-generic-i686-athlon-with-Ubuntu-16.04-xenial'


os platform


🐍 You might also find interesting: