all Python 3platformfunction
platform.python_version()
interpreter
The Python version as a 'major.minor.patch' string, e.g. '3.14.0'; the patch level is always present, even when it is 0.
Syntax
platform.python_version()
Never compare it as a string: '3.9.0' > '3.14.0' is true because the comparison goes character by character. To check the version in code use the tuple of integers sys.version_info >= (3, 12), and keep python_version() for display. Pre-releases carry a suffix: '3.15.0a1'.
Examples
import platform, sys
print(platform.python_version()) # → ? например 3.14.0
print('3.9.0' > '3.14.0') # → True — строки сравниваются посимвольно
print(sys.version_info >= (3, 9)) # → True — так сравнивать правильно
See also
Open in the full glossarydocs.python.orgReport an inaccuracy