Python Practice › sys Module Programs › Program 5
Detect the operating system
Write a Python program that prints a different message per operating system.
Output
Windows
Approach
sys.platformis “win32”, “linux” or “darwin”.
Solution
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.