Boolean对象

Python中的布尔值作为一个子类的整数实现。只有两个布尔值:Py_False 和 Py_True。 因此,正常的创造和删除功能不适用于布尔值,然而有以下的宏。

PyTypeObject PyBool_Type
Part of the Stable ABI.

This instance of PyTypeObject represents the Python boolean type; it is the same object as bool in the Python layer.

int PyBool_Check(PyObject *o)

Return true if o is of type PyBool_Type. This function always succeeds.

PyObject *Py_False

The Python False object. This object has no methods and is immortal.

在 3.12 版本发生变更: Py_False is immortal.

PyObject *Py_True

The Python True object. This object has no methods and is immortal.

在 3.12 版本发生变更: Py_True is immortal.

Py_RETURN_FALSE

从一个函数返回 Py_False 。

Py_RETURN_TRUE

从一个函数返回 Py_True 。

PyObject *PyBool_FromLong(long v)
Return value: New reference. Part of the Stable ABI.

返回 Py_True 或 Py_False,取决于*v*的真实值。