CPython exposes its version number in the following macros. Note that these correspond to the version code is built with, not necessarily the version used at run time .
见 C API 稳定性 for a discussion of API and ABI stability across versions.
The
3
in
3.4.1a2
.
The
4
in
3.4.1a2
.
The
1
in
3.4.1a2
.
The
a
in
3.4.1a2
. This can be
0xA
对于 Alpha,
0xB
对于 Beta,
0xC
for release candidate or
0xF
for final.
The
2
in
3.4.1a2
. Zero for final releases.
The Python version number encoded in a single integer.
The underlying version information can be found by treating it as a 32 bit number in the following manner:
|
字节 |
位数 (大端在前次序) |
含义 |
Value for
|
|---|---|---|---|
| 1 | 1-8 |
|
|
| 2 | 9-16 |
|
|
| 3 | 17-24 |
|
|
|
4 |
25-28 |
|
|
| 29-32 |
|
|
因此
3.4.1a2
是十六进制
0x030401a2
and
3.10.0
是十六进制
0x030a00f0
.
Use this for numeric comparisons, e.g.
#if PY_VERSION_HEX >= ...
.
This version is also available via the symbol
Py_Version
.
The Python runtime version number encoded in a single constant integer, with the same format as the
PY_VERSION_HEX
macro. This contains the Python version used at run time.
Added in version 3.11.
所有给定宏的定义在 Include/patchlevel.h .