How to check the operating system name and version in Python?
How to check the operating system name and version in Python?
511
13-Jul-2023
Updated on 14-Jul-2023
Aryan Kumar
14-Jul-2023Sure, here is how to check the OS name and version in Python:
Python
This code will first import the
platformmodule. Theplatformmodule provides information about the operating system and hardware that the code is running on.Next, the code will define a function called
get_os_name_and_version(). This function will get the OS name and version and return them as a tuple.The
get_os_name_and_version()function uses theplatform.system()andplatform.release()methods to get the OS name and version. Theplatform.system()method returns the name of the operating system, and theplatform.release()method returns the version of the operating system.Finally, the code will call the
get_os_name_and_version()function and print the OS name and version to the console.Here is an example of the output of this code:
This output shows that the computer is running Windows 10, version 20H2.