What is winreg.DeleteKey in Python?
winreg (Windows Registry API) provides functions to expose the Windows Registry API to Python. We use this module to expose a low-level interface to the registry.
DeleteKey
We use the method DeleteKey to remove any specified key. The method takes the key and sub_key as parameters. Using this method removes a key and its values. Otherwise, the method raises an OSError exception.
Syntax
winreg.DeleteKey(key, sub_key)
Parameters
key: Any open HKEY_* constant or one of the predefined HKEY_* constants can be given as a parameter to the method.
sub_key: This is the subkey of any given key. It is a string value. This parameter cannot be None.
The method cannot delete keys that have subkeys. In that situation, the subkeys must be removed first before deleting the key.
Free Resources
Copyright ©2026 Educative, Inc. All rights reserved