To determine the operating system in Python, you can utilize the sys.platform attribute provided by the sys module. By examining the value of sys.platform, you can identify the underlying operating system. Here's an alternative phrasing:
import sys
platform = sys.platform
if platform.startswith('win'):
print("Windows")
elif platform.startswith('linux'):
print("Linux")
elif platform.startswith('darwin'):
print("Mac")
else:
print("Unknown")
By evaluating the value of sys.platform, the code determines whether it starts with 'win', 'linux', or 'darwin', which correspond to Windows, Linux, and macOS (Mac), respectively. For any other platform, it is considered unknown. The operating system name is then displayed based on the identified platform.