blob: fede3484e6c4abbf89a0170e534b032d376221a6 [file] [log] [blame]
Georg Brandlf6842722008-01-19 22:08:21 +00001.. highlightlang:: c
2
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
Sandro Tosi98ed08f2012-01-14 16:42:02 +010014.. c:function:: int PyBool_Check(PyObject *o)
Georg Brandlf6842722008-01-19 22:08:21 +000015
Sandro Tosi98ed08f2012-01-14 16:42:02 +010016 Return true if *o* is of type :c:data:`PyBool_Type`.
Georg Brandlf6842722008-01-19 22:08:21 +000017
18 .. versionadded:: 2.3
19
20
Sandro Tosi98ed08f2012-01-14 16:42:02 +010021.. c:var:: PyObject* Py_False
Georg Brandlf6842722008-01-19 22:08:21 +000022
23 The Python ``False`` object. This object has no methods. It needs to be
24 treated just like any other object with respect to reference counts.
25
26
Sandro Tosi98ed08f2012-01-14 16:42:02 +010027.. c:var:: PyObject* Py_True
Georg Brandlf6842722008-01-19 22:08:21 +000028
29 The Python ``True`` object. This object has no methods. It needs to be treated
30 just like any other object with respect to reference counts.
31
32
Sandro Tosi98ed08f2012-01-14 16:42:02 +010033.. c:macro:: Py_RETURN_FALSE
Georg Brandlf6842722008-01-19 22:08:21 +000034
35 Return :const:`Py_False` from a function, properly incrementing its reference
36 count.
37
38 .. versionadded:: 2.4
39
40
Sandro Tosi98ed08f2012-01-14 16:42:02 +010041.. c:macro:: Py_RETURN_TRUE
Georg Brandlf6842722008-01-19 22:08:21 +000042
43 Return :const:`Py_True` from a function, properly incrementing its reference
44 count.
45
46 .. versionadded:: 2.4
47
48
Sandro Tosi98ed08f2012-01-14 16:42:02 +010049.. c:function:: PyObject* PyBool_FromLong(long v)
Georg Brandlf6842722008-01-19 22:08:21 +000050
51 Return a new reference to :const:`Py_True` or :const:`Py_False` depending on the
52 truth value of *v*.
53
54 .. versionadded:: 2.3