summaryrefslogtreecommitdiffstats
path: root/Doc/c-api/bool.rst
blob: b4dc4849d044e1c6c3a3b215c30258769f17f39a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
.. highlight:: c

.. _boolobjects:

Boolean Objects
---------------

Booleans in Python are implemented as a subclass of integers.  There are only
two booleans, :c:data:`Py_False` and :c:data:`Py_True`.  As such, the normal
creation and deletion functions don't apply to booleans.  The following macros
are available, however.


.. c:var:: PyTypeObject PyBool_Type

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


.. c:function:: int PyBool_Check(PyObject *o)

   Return true if *o* is of type :c:data:`PyBool_Type`.  This function always
   succeeds.


.. c:var:: PyObject* Py_False

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

   .. versionchanged:: 3.12
      :c:data:`Py_False` is :term:`immortal`.


.. c:var:: PyObject* Py_True

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

   .. versionchanged:: 3.12
      :c:data:`Py_True` is :term:`immortal`.


.. c:macro:: Py_RETURN_FALSE

   Return :c:data:`Py_False` from a function.


.. c:macro:: Py_RETURN_TRUE

   Return :c:data:`Py_True` from a function.


.. c:function:: PyObject* PyBool_FromLong(long v)

   Return :c:data:`Py_True` or :c:data:`Py_False`, depending on the truth value of *v*.