Boolean(布林)物件

Python 中的 boolean 是以整數子類別化來實現的。只有 Py_FalsePy_True 兩個 boolean。因此一般的建立和刪除函式並不適用於 boolean。但下列巨集 (macro) 是可用的。

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)

如果 o 的型別為 PyBool_Type 則回傳真值。此函式總是會成功執行。

PyObject *Py_False

Python 的 False 物件。此物件沒有任何方法。在參照 (reference) 計數上必須有著和其他物件一樣的處理方式。

PyObject *Py_True

Python 的 True 物件。此物件沒有任何方法。在參照計數上必須有著和其他物件一樣的處理方式。

Py_RETURN_FALSE

從函式回傳 Py_False,並適當的增加它的參照計數。

Py_RETURN_TRUE

從函式回傳 Py_True,並適當的增加它的參照計數。

PyObject *PyBool_FromLong(long v)
回傳值:新的參照。 Part of the Stable ABI.

根據 v 的實際值來回傳一個 Py_True 或者 Py_False 的新參照。