Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 1 | |
| 2 | Built-in Constants |
| 3 | ================== |
| 4 | |
| 5 | A small number of constants live in the built-in namespace. They are: |
| 6 | |
| 7 | |
Georg Brandl | 96593ed | 2007-09-07 14:15:41 +0000 | [diff] [blame] | 8 | .. note:: |
| 9 | |
| 10 | :data:`None`, :data:`False`, :data:`True` and :data:`__debug__` cannot be |
Georg Brandl | 18a499d | 2007-12-29 10:57:11 +0000 | [diff] [blame] | 11 | reassigned (assignments to them raise :exc:`SyntaxError`), so they can be |
| 12 | considered "true" constants. |
Georg Brandl | 96593ed | 2007-09-07 14:15:41 +0000 | [diff] [blame] | 13 | |
Georg Brandl | 55ac8f0 | 2007-09-01 13:51:09 +0000 | [diff] [blame] | 14 | .. XXX False, True, None are keywords too |
| 15 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 16 | .. data:: False |
| 17 | |
Christian Heimes | 5b5e81c | 2007-12-31 16:14:33 +0000 | [diff] [blame^] | 18 | The false value of the :class:`bool` type. Assignments to ``False`` |
| 19 | are illegal and raise a :exc:`SyntaxError`. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 20 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 21 | |
| 22 | .. data:: True |
| 23 | |
Christian Heimes | 5b5e81c | 2007-12-31 16:14:33 +0000 | [diff] [blame^] | 24 | The true value of the :class:`bool` type. Assignments to ``True`` |
| 25 | are illegal and raise a :exc:`SyntaxError`. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 26 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 27 | |
| 28 | .. data:: None |
| 29 | |
| 30 | The sole value of :attr:`types.NoneType`. ``None`` is frequently used to |
| 31 | represent the absence of a value, as when default arguments are not passed to a |
Christian Heimes | 5b5e81c | 2007-12-31 16:14:33 +0000 | [diff] [blame^] | 32 | function. Assignments to ``None`` are illegal and raise a :exc:`SyntaxError`. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 33 | |
| 34 | |
| 35 | .. data:: NotImplemented |
| 36 | |
| 37 | Special value which can be returned by the "rich comparison" special methods |
| 38 | (:meth:`__eq__`, :meth:`__lt__`, and friends), to indicate that the comparison |
| 39 | is not implemented with respect to the other type. |
| 40 | |
| 41 | |
| 42 | .. data:: Ellipsis |
| 43 | |
| 44 | The same as ``...``. Special value used mostly in conjunction with extended |
Georg Brandl | cb8ecb1 | 2007-09-04 06:35:14 +0000 | [diff] [blame] | 45 | slicing syntax for user-defined container data types, as in :: |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 46 | |
Christian Heimes | 5b5e81c | 2007-12-31 16:14:33 +0000 | [diff] [blame^] | 47 | .. XXX Someone who understands extended slicing should fill in here. |
Georg Brandl | 96593ed | 2007-09-07 14:15:41 +0000 | [diff] [blame] | 48 | |
| 49 | |
| 50 | .. data:: __debug__ |
| 51 | |
Christian Heimes | 5b5e81c | 2007-12-31 16:14:33 +0000 | [diff] [blame^] | 52 | This constant is true if Python was not started with an :option:`-O` option. |
| 53 | Assignments to :const:`__debug__` are illegal and raise a :exc:`SyntaxError`. |
| 54 | See also the :keyword:`assert` statement. |