all Python 3platformfunction
platform.python_version_tuple()
interpreter
The Python version as a tuple of three STRINGS: ('3', '14', '0'). Unsuitable for comparing versions; use sys.version_info.
Syntax
major, minor, patch = platform.python_version_tuple()
The main trap is that the items are strings while tuples compare item by item: ('3', '14', '0') > ('3', '9') is false because '14' < '9' as strings. Such a 'Python at least 3.9' check silently gives the wrong answer on every version with a two-digit minor. sys.version_info holds integers and compares correctly.
Examples
import platform, sys
print(type(platform.python_version_tuple()[1]).__name__) # → str
print(platform.python_version_tuple() > ('3', '9')) # → False — '14' < '9' как строки
print(sys.version_info > (3, 9)) # → True
See also
Open in the full glossarydocs.python.orgReport an inaccuracy