Detect the operating system

Easysys Module Programs · 5 of 20

Write a Python program that prints a different message per operating system.

Advertisement
Output
Windows

Approach

  1. sys.platform is “win32”, “linux” or “darwin”.

Solution

Python
import sys if sys.platform.startswith("win"):    print("Windows")elif sys.platform == "darwin":    print("macOS")else:    print("Linux or another Unix")
Output
Windows

Learn the concept

New to this topic? Read the lesson, then come back.

More sys module programs

← All 20 sys Module Programs

Leave a Comment