platform() function, which gathers comprehensive details about the underlying platform. It offers customization through parameters such as alias and terse to alter the output format.
For example, the following code prints a detailed description of the current platform:
Using the
alias parameter, when set to True, displays alternative underlying names, while the terse parameter produces a more compact output. The behavior of these parameters may vary across different platforms.Other Useful Functions in the Platform Module
In addition to theplatform() function, the module provides several other utility functions to fetch specific system details:
-
Machine Type:
Themachine()function returns a string identifying the machine type (e.g., “x86_64”). -
Processor Details:
Theprocessor()function offers information about the processor. -
Operating System Name:
Thesystem()function returns the name of the operating system (e.g., “Linux”, “Windows”, or “Darwin”). -
Operating System Version:
Theversion()function provides detailed version information of the operating system.
Retrieving Python Version Information
It is often valuable to determine the Python version in use. The platform module offers multiple functions for this purpose:-
Python Implementation:
Thepython_implementation()function returns a string indicating the Python implementation (such as “CPython”, “PyPy”, etc.): -
Python Version Tuple:
Thepython_version_tuple()function returns a tuple of strings containing the major, minor, and patch level versions of Python:
Now is the perfect time to practice using these functions in your projects. Experiment with different outputs and explore how they change across different platforms.