What is the platform.platform() method in Python?

Overview

The platform module in Python provides functions that access information of the underlying platform (operating system).

The platform.platform() method returns a single string containing as much information about the underlying platform as feasible. The output is meant to be viewable by humans rather than machines.

Syntax

platform(aliased=0, terse=0)

Parameters

  • aliased: Setting this parameter to True indicates the function to use aliases for different platforms than their common names. For example, SunOS will be reported as Solaris.
  • terse: Setting this parameter to True will make the function return minimal information about the platform.

Return value

This method returns the human readable single string about the underlying platform.

Code

Let’s look at the code below:

import platform
plat_str = platform.platform()
print("platform.platform() = %s" % (plat_str))
min_plat_str = platform.platform(terse=1)
print("platform.platform(terse=1) = %s" % (min_plat_str))

Explanation

  • Lines 3 to 5: We print the output of the platform.platform() method.
  • Lines 7 to 9: We print the output of the platform.platform(terse=1) method with the terse parameter as True is printed.

When we enable the terse parameter, it prints minimal information about the platform in the output.

New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources