Python sys.platform Variable

Python sys.platform Variable

  1. Syntax
  2. Parameters
  3. Returns
  4. Example Codes Demonstrating the Use of sys.platofrm

Python sys.platform is an efficient way to get information about the platform used. It also returns the platform identifier we can use to change and edit some OS-specific components like sys.path, for instance.

Syntax

sys.platform

Parameters

no parameters It is a non-callable object.

Returns

The sys.platform return type is a string containing a platform identifier for OS in use. The list below mentions some of the OS platforms and their returned value:

System Platform Value
Linux linux or linux2
Windows win32
Windows/Cygwin cygwin
Windows/MSYS2 msys
Mac OS X darwin

Example Codes Demonstrating the Use of sys.platofrm

Use the sys.platform on LINUX

import sys
print (sys.platform)

Output:

linux

The above code is executed on a LINUX platform, so the method returns that specific platform identifier.

Use the sys.platform on Windows OS

import sys
print (sys.platform)

Output:

win32

The above code is executed on a WINDOWS platform, so the method returns that specific platform identifier.

Use the sys.platform Variable With Other Similar Variables & Methods

import sys
import platform
import os
print (sys.platform)
print (os.name)
print (platform.system)

Output:

win32
nt
<function system at 0x000001C2D2439750>

The sys.platform gives us information about the build configuration. On the other hand, the os.name checks for the availability of specific os-specific modules such as POSIX, nt, etc.

And the platform.system method determines the system type at run time.

Musfirah Waseem avatar Musfirah Waseem avatar

Musfirah is a student of computer science from the best university in Pakistan. She has a knack for programming and everything related. She is a tech geek who loves to help people as much as possible.

LinkedIn

Related Article - Python Sys

  • Python sys.stdin Attribute
  • Python sys.argv List
  • Python sys.maxsize() Method
  • Python sys.stdout Method
  • Python sys.exit() Method
  • Python sys.path Attribute