platform.python_version
Prev: platform.python_revision | Up: platform | Next: platform.python_version_tuple
Rel: platform.android_ver, platform.AndroidVer, platform.architecture, platform.freedesktop_os_release
Ref: docs.python.org — platform.python_version
Tags: #public #python3 #stdlib #platform
Import
import platform
from platform import python_version
Signature & Overview
platform.python_version()
Returns the Python version as string 'major.minor.patchlevel' Note that unlike the Python sys.version, the returned value will always include the patchlevel (it defaults to 0).
Usage
import platform
v = platform.python_version()
assert v.startswith("3.")
Gotchas
- Use
sys.version_info >= (3, 11)for comparisons, NOT string comparison onpython_version()(because"3.9" > "3.12"alphabetically!).
REPL Inspect
from platform import python_version
help(python_version)
Linked from
Related notes
- tuts/python3/stdlib_module/platform/python_revision Linked here; links to this page; shared tags: #platform, #stdlib
- tuts/python3/stdlib_module/platform/python_version_tuple Linked here; links to this page; shared tags: #platform, #stdlib
- tuts/python3/stdlib_module/platform/android_ver Linked here; shared tags: #platform, #stdlib
- tuts/python3/stdlib_module/platform/AndroidVer Linked here; shared tags: #platform, #stdlib
- tuts/python3/stdlib_module/platform/architecture Linked here; shared tags: #platform, #stdlib
- tuts/python3/stdlib_module/platform/freedesktop_os_release Linked here; shared tags: #platform, #stdlib
- tuts/python3/stdlib_module/platform/platform Linked here; shared tags: #platform, #stdlib
- tuts/python3/stdlib_module/platform links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/platform/invalidate_caches shared tags: #platform, #stdlib
- tuts/python3/stdlib_module/platform/ios_ver shared tags: #platform, #stdlib