Boolean Objects

Booleans in Python are implemented as a subclass of integers. There are onlytwo booleans,Py_False andPy_True. As such, the normalcreation and deletion functions don’t apply to booleans. The following macrosare available, however.

PyTypeObjectPyBool_Type
Part of theStable ABI.

This instance ofPyTypeObject represents the Python boolean type; itis the same object asbool in the Python layer.

intPyBool_Check(PyObject*o)

Return true ifo is of typePyBool_Type. This function alwayssucceeds.

PyObject*Py_False

The PythonFalse object. This object has no methods and isimmortal.

Changed in version 3.12:Py_False isimmortal.

PyObject*Py_True

The PythonTrue object. This object has no methods and isimmortal.

Changed in version 3.12:Py_True isimmortal.

Py_RETURN_FALSE

ReturnPy_False from a function.

Py_RETURN_TRUE

ReturnPy_True from a function.

PyObject*PyBool_FromLong(longv)
Return value: New reference. Part of theStable ABI.

ReturnPy_True orPy_False, depending on the truth value ofv.