[파이썬] `sys.getwindowsversion()`: 윈도우 버전 튜플 반환 (Windows 전용)

To use sys.getwindowsversion(), you first need to import the sys module. Here’s a simple example that demonstrates how to use this function:

import sys

# Get the Windows version tuple
windows_version = sys.getwindowsversion()

# Print the Windows version information
print(f"Major version: {windows_version.major}")
print(f"Minor version: {windows_version.minor}")
print(f"Build number: {windows_version.build}")
print(f"Platform ID: {windows_version.platform}")
print(f"Service pack: {windows_version.service_pack}")

The output of this code will provide you with information about the version of Windows you are running. Here’s an example output:

Major version: 10
Minor version: 0
Build number: 19042
Platform ID: 2
Service pack: Service Pack 0

In the example above, the sys.getwindowsversion() function returns a tuple containing the major version, minor version, build number, platform ID, and service pack information of the Windows operating system. By accessing the individual elements of the tuple, you can extract and use this information as needed in your Python program.

The sys.getwindowsversion() function is particularly useful if your code needs to perform certain actions or make decisions based on the specific version of Windows. It allows you to write platform-specific code and adapt your program’s behavior accordingly.

By utilizing the sys.getwindowsversion() function in Python, you can effortlessly retrieve the version of Windows you are working with and take appropriate actions based on that information.