| 1 |
.. highlight:: c |
| 2 |
|
| 3 |
.. _boolobjects: |
| 4 |
|
| 5 |
Boolean Objects |
| 6 |
--------------- |
| 7 |
|
| 8 |
Booleans in Python are implemented as a subclass of integers. There are only |
| 9 |
two booleans, :c:data:`Py_False` and :c:data:`Py_True`. As such, the normal |
| 10 |
creation and deletion functions don't apply to booleans. The following macros |
| 11 |
are available, however. |
| 12 |
|
| 13 |
|
| 14 |
.. c:var:: PyTypeObject PyBool_Type |
| 15 |
|
| 16 |
This instance of :c:type:`PyTypeObject` represents the Python boolean type; it |
| 17 |
is the same object as :class:`bool` in the Python layer. |
| 18 |
|
| 19 |
|
| 20 |
.. c:function:: int PyBool_Check(PyObject *o) |
| 21 |
|
| 22 |
Return true if *o* is of type :c:data:`PyBool_Type`. This function always |
| 23 |
succeeds. |
| 24 |
|
| 25 |
|
| 26 |
.. c:var:: PyObject* Py_False |
| 27 |
|
| 28 |
The Python ``False`` object. This object has no methods and is |
| 29 |
:term:`immortal`. |
| 30 |
|
| 31 |
.. versionchanged:: 3.12 |
| 32 |
:c:data:`Py_False` is :term:`immortal`. |
| 33 |
|
| 34 |
|
| 35 |
.. c:var:: PyObject* Py_True |
| 36 |
|
| 37 |
The Python ``True`` object. This object has no methods and is |
| 38 |
:term:`immortal`. |
| 39 |
|
| 40 |
.. versionchanged:: 3.12 |
| 41 |
:c:data:`Py_True` is :term:`immortal`. |
| 42 |
|
| 43 |
|
| 44 |
.. c:macro:: Py_RETURN_FALSE |
| 45 |
|
| 46 |
Return :c:data:`Py_False` from a function. |
| 47 |
|
| 48 |
|
| 49 |
.. c:macro:: Py_RETURN_TRUE |
| 50 |
|
| 51 |
Return :c:data:`Py_True` from a function. |
| 52 |
|
| 53 |
|
| 54 |
.. c:function:: PyObject* PyBool_FromLong(long v) |
| 55 |
|
| 56 |
Return :c:data:`Py_True` or :c:data:`Py_False`, depending on the truth value of *v*. |