w3resource

Python: Find the operating system name, platform and platform release date

Python Basic: Exercise-142 with Solution

Write a Python program to find the operating system name, platform and platform release date.

Sample Solution-1:

Python Code:

import os, platform
print("Operating system name:")
print(os.name)
print("Platform name:")
print(platform.system())
print("Platform release:")
print(platform.release())

Sample Output:

Operating system name:                                                  
posix                                                                   
Platform name:                                                          
Linux                                                                   
Platform release:                                                       
4.4.0-47-generic 

Sample Solution-2:

Python Code:

import os
import sys
import platform
import sysconfig
print("os.name                     ", os.name)
print("sys.platform                ", sys.platform)
print("platform.system()           ", platform.system())
print("sysconfig.get_platform()    ", sysconfig.get_platform())
print("platform.machine()          ", platform.machine())
print("platform.architecture()     ", platform.architecture())

Sample Output:

os.name                      posix
sys.platform                 linux
platform.system()            Linux
sysconfig.get_platform()     linux-x86_64
platform.machine()           x86_64
platform.architecture()      ('64bit', 'ELF') 

Python Code Editor:

 

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a python program to convert decimal to hexadecimal.
Next: Write a Python program to determine if the python shell is executing in 32bit or 64bit mode on operating system.

What is the difficulty level of this exercise?

Test your Python skills with w3resource's quiz



Python: Tips of the Day

List comprehension:

>>> m = [x ** 2 for x in range(5)]
>>> m
[0, 1, 4, 9, 16]