| 
									
										
										
										
											2019-05-17 11:55:34 +02:00
										 |  |  | .. highlight:: c
 | 
					
						
							| 
									
										
										
										
											2008-01-20 09:30:57 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | .. _boolobjects:
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Boolean Objects
 | 
					
						
							|  |  |  | ---------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Booleans in Python are implemented as a subclass of integers.  There are only
 | 
					
						
							| 
									
										
										
										
											2023-06-21 21:13:25 +01:00
										 |  |  | two booleans, :c:data:`Py_False` and :c:data:`Py_True`.  As such, the normal
 | 
					
						
							| 
									
										
										
										
											2008-01-20 09:30:57 +00:00
										 |  |  | creation and deletion functions don't apply to booleans.  The following macros
 | 
					
						
							|  |  |  | are available, however.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-29 08:48:10 +03:00
										 |  |  | .. 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.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-06 10:11:56 +00:00
										 |  |  | .. c:function:: int PyBool_Check(PyObject *o)
 | 
					
						
							| 
									
										
										
										
											2008-01-20 09:30:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-06 12:38:26 +01:00
										 |  |  |    Return true if *o* is of type :c:data:`PyBool_Type`.  This function always
 | 
					
						
							|  |  |  |    succeeds.
 | 
					
						
							| 
									
										
										
										
											2008-01-20 09:30:57 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-06 10:11:56 +00:00
										 |  |  | .. c:var:: PyObject* Py_False
 | 
					
						
							| 
									
										
										
										
											2008-01-20 09:30:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-21 21:13:25 +01:00
										 |  |  |    The Python ``False`` object.  This object has no methods and is
 | 
					
						
							| 
									
										
										
										
											2023-11-17 15:09:19 +01:00
										 |  |  |    :term:`immortal`.
 | 
					
						
							| 
									
										
										
										
											2023-06-21 21:13:25 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-17 15:09:19 +01:00
										 |  |  |    .. versionchanged:: 3.12
 | 
					
						
							|  |  |  |       :c:data:`Py_False` is :term:`immortal`.
 | 
					
						
							| 
									
										
										
										
											2008-01-20 09:30:57 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-06 10:11:56 +00:00
										 |  |  | .. c:var:: PyObject* Py_True
 | 
					
						
							| 
									
										
										
										
											2008-01-20 09:30:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-21 21:13:25 +01:00
										 |  |  |    The Python ``True`` object.  This object has no methods and is
 | 
					
						
							| 
									
										
										
										
											2023-11-17 15:09:19 +01:00
										 |  |  |    :term:`immortal`.
 | 
					
						
							| 
									
										
										
										
											2023-06-21 21:13:25 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-17 15:09:19 +01:00
										 |  |  |    .. versionchanged:: 3.12
 | 
					
						
							|  |  |  |       :c:data:`Py_True` is :term:`immortal`.
 | 
					
						
							| 
									
										
										
										
											2008-01-20 09:30:57 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-06 10:11:56 +00:00
										 |  |  | .. c:macro:: Py_RETURN_FALSE
 | 
					
						
							| 
									
										
										
										
											2008-01-20 09:30:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-21 21:13:25 +01:00
										 |  |  |    Return :c:data:`Py_False` from a function.
 | 
					
						
							| 
									
										
										
										
											2008-01-20 09:30:57 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-06 10:11:56 +00:00
										 |  |  | .. c:macro:: Py_RETURN_TRUE
 | 
					
						
							| 
									
										
										
										
											2008-01-20 09:30:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-21 21:13:25 +01:00
										 |  |  |    Return :c:data:`Py_True` from a function.
 | 
					
						
							| 
									
										
										
										
											2008-01-20 09:30:57 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-06 10:11:56 +00:00
										 |  |  | .. c:function:: PyObject* PyBool_FromLong(long v)
 | 
					
						
							| 
									
										
										
										
											2008-01-20 09:30:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-21 21:13:25 +01:00
										 |  |  |    Return :c:data:`Py_True` or :c:data:`Py_False`, depending on the truth value of *v*.
 |