blob: c197d447e9618c9998851c7fe2c6d1df5aefd731 [file] [log] [blame]
Stéphane Wirtelcbb64842019-05-17 11:55:34 +02001.. highlight:: c
Georg Brandl54a3faa2008-01-20 09:30:57 +00002
3.. _boolobjects:
4
5Boolean Objects
6---------------
7
8Booleans in Python are implemented as a subclass of integers. There are only
9two booleans, :const:`Py_False` and :const:`Py_True`. As such, the normal
10creation and deletion functions don't apply to booleans. The following macros
11are available, however.
12
13
Georg Brandl60203b42010-10-06 10:11:56 +000014.. c:function:: int PyBool_Check(PyObject *o)
Georg Brandl54a3faa2008-01-20 09:30:57 +000015
Antonio Cuni315fc522021-01-06 12:38:26 +010016 Return true if *o* is of type :c:data:`PyBool_Type`. This function always
17 succeeds.
Georg Brandl54a3faa2008-01-20 09:30:57 +000018
19
Georg Brandl60203b42010-10-06 10:11:56 +000020.. c:var:: PyObject* Py_False
Georg Brandl54a3faa2008-01-20 09:30:57 +000021
22 The Python ``False`` object. This object has no methods. It needs to be
23 treated just like any other object with respect to reference counts.
24
25
Georg Brandl60203b42010-10-06 10:11:56 +000026.. c:var:: PyObject* Py_True
Georg Brandl54a3faa2008-01-20 09:30:57 +000027
28 The Python ``True`` object. This object has no methods. It needs to be treated
29 just like any other object with respect to reference counts.
30
31
Georg Brandl60203b42010-10-06 10:11:56 +000032.. c:macro:: Py_RETURN_FALSE
Georg Brandl54a3faa2008-01-20 09:30:57 +000033
34 Return :const:`Py_False` from a function, properly incrementing its reference
35 count.
36
37
Georg Brandl60203b42010-10-06 10:11:56 +000038.. c:macro:: Py_RETURN_TRUE
Georg Brandl54a3faa2008-01-20 09:30:57 +000039
40 Return :const:`Py_True` from a function, properly incrementing its reference
41 count.
42
43
Georg Brandl60203b42010-10-06 10:11:56 +000044.. c:function:: PyObject* PyBool_FromLong(long v)
Georg Brandl54a3faa2008-01-20 09:30:57 +000045
46 Return a new reference to :const:`Py_True` or :const:`Py_False` depending on the
47 truth value of *v*.