> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Platform Module

> The article explains the Python platform module for accessing system information and adapting programs to different hardware and operating systems.

Determining the system platform is essential when writing programs that need to adapt to different hardware, operating systems, or Python interpreters. The Python [platform module](https://docs.python.org/3/library/platform.html) provides a convenient way to access this system information.

One of the most commonly used functions is the `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:

```python theme={null}
from platform import platform
print(platform())
```

Example output:

```text theme={null}
Linux-5.11.0-1018-gcp-x86_64-with-glibc2.27
```

<Callout icon="lightbulb" color="#1CB2FE">
  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.
</Callout>

## Other Useful Functions in the Platform Module

In addition to the `platform()` function, the module provides several other utility functions to fetch specific system details:

* **Machine Type:**\
  The `machine()` function returns a string identifying the machine type (e.g., "x86\_64").

* **Processor Details:**\
  The `processor()` function offers information about the processor.

* **Operating System Name:**\
  The `system()` function returns the name of the operating system (e.g., "Linux", "Windows", or "Darwin").

* **Operating System Version:**\
  The `version()` function provides detailed version information of the operating system.

For example, to retrieve and print the operating system name, use the following code:

```python theme={null}
from platform import system
print(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:**\
  The `python_implementation()` function returns a string indicating the Python implementation (such as "CPython", "PyPy", etc.):

  ```python theme={null}
  from platform import python_implementation
  print(python_implementation())
  ```

* **Python Version Tuple:**\
  The `python_version_tuple()` function returns a tuple of strings containing the major, minor, and patch level versions of Python:

  ```python theme={null}
  from platform import python_version_tuple
  print(python_version_tuple())
  ```

This comprehensive functionality facilitates the development of cross-platform applications by adapting behavior based on the environment.

<Callout icon="lightbulb" color="#1CB2FE">
  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.
</Callout>

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/pcap-python-certification-course/module/a65eb782-d2dc-4850-9046-e4bb57d38876/lesson/76c926c0-d64d-4e48-bb2b-3e7bf7251a38" />

  <Card title="Practice Lab" icon="installation" cta="Learn more" href="https://learn.kodekloud.com/user/courses/pcap-python-certification-course/module/a65eb782-d2dc-4850-9046-e4bb57d38876/lesson/0efa3fee-f05a-4348-b5a0-f1256f2132a9" />
</CardGroup>
