| Éric Araujo | 96deb75 | 2011-06-08 04:53:20 +0200 | [diff] [blame] | 1 | .. _built-in-consts: | 
 | 2 |  | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 3 | Built-in Constants | 
 | 4 | ================== | 
 | 5 |  | 
 | 6 | A small number of constants live in the built-in namespace.  They are: | 
 | 7 |  | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 8 | .. data:: False | 
 | 9 |  | 
| Georg Brandl | 48310cd | 2009-01-03 21:18:54 +0000 | [diff] [blame] | 10 |    The false value of the :class:`bool` type. Assignments to ``False`` | 
| Christian Heimes | 5b5e81c | 2007-12-31 16:14:33 +0000 | [diff] [blame] | 11 |    are illegal and raise a :exc:`SyntaxError`. | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 12 |  | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 13 |  | 
 | 14 | .. data:: True | 
 | 15 |  | 
| Georg Brandl | 48310cd | 2009-01-03 21:18:54 +0000 | [diff] [blame] | 16 |    The true value of the :class:`bool` type. Assignments to ``True`` | 
| Christian Heimes | 5b5e81c | 2007-12-31 16:14:33 +0000 | [diff] [blame] | 17 |    are illegal and raise a :exc:`SyntaxError`. | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 18 |  | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 19 |  | 
 | 20 | .. data:: None | 
 | 21 |  | 
| R David Murray | e60e12b | 2012-07-22 20:43:13 -0400 | [diff] [blame] | 22 |    The sole value of the type ``NoneType``.  ``None`` is frequently used to | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 23 |    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] | 24 |    function. Assignments to ``None`` are illegal and raise a :exc:`SyntaxError`. | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 25 |  | 
 | 26 |  | 
 | 27 | .. data:: NotImplemented | 
 | 28 |  | 
| Ethan Furman | b004943 | 2014-11-26 21:15:35 -0800 | [diff] [blame] | 29 |    Special value which should be returned by the binary special methods | 
 | 30 |    (e.g. :meth:`__eq__`, :meth:`__lt__`, :meth:`__add__`, :meth:`__rsub__`, | 
 | 31 |    etc.) to indicate that the operation is not implemented with respect to | 
 | 32 |    the other type; may be returned by the in-place binary special methods | 
 | 33 |    (e.g. :meth:`__imul__`, :meth:`__iand__`, etc.) for the same purpose. | 
 | 34 |    Its truth value is true. | 
 | 35 |  | 
| Ethan Furman | 20bd9f0 | 2016-08-05 15:10:16 -0700 | [diff] [blame] | 36 |    .. note:: | 
| Ethan Furman | b004943 | 2014-11-26 21:15:35 -0800 | [diff] [blame] | 37 |  | 
| Ethan Furman | 20bd9f0 | 2016-08-05 15:10:16 -0700 | [diff] [blame] | 38 |       When a binary (or in-place) method returns ``NotImplemented`` the | 
 | 39 |       interpreter will try the reflected operation on the other type (or some | 
 | 40 |       other fallback, depending on the operator).  If all attempts return | 
 | 41 |       ``NotImplemented``, the interpreter will raise an appropriate exception. | 
 | 42 |       Incorrectly returning ``NotImplemented`` will result in a misleading | 
 | 43 |       error message or the ``NotImplemented`` value being returned to Python code. | 
| Ethan Furman | b004943 | 2014-11-26 21:15:35 -0800 | [diff] [blame] | 44 |  | 
| Ethan Furman | 20bd9f0 | 2016-08-05 15:10:16 -0700 | [diff] [blame] | 45 |       See :ref:`implementing-the-arithmetic-operations` for examples. | 
 | 46 |  | 
 | 47 |    .. note:: | 
 | 48 |  | 
 | 49 |       ``NotImplentedError`` and ``NotImplemented`` are not interchangeable, | 
 | 50 |       even though they have similar names and purposes. | 
 | 51 |       See :exc:`NotImplementedError` for details on when to use it. | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 52 |  | 
 | 53 |  | 
 | 54 | .. data:: Ellipsis | 
 | 55 |  | 
| Georg Brandl | 9499bb7 | 2010-08-02 19:35:06 +0000 | [diff] [blame] | 56 |    The same as ``...``.  Special value used mostly in conjunction with extended | 
 | 57 |    slicing syntax for user-defined container data types. | 
| Georg Brandl | 96593ed | 2007-09-07 14:15:41 +0000 | [diff] [blame] | 58 |  | 
 | 59 |  | 
 | 60 | .. data:: __debug__ | 
 | 61 |  | 
| Christian Heimes | 5b5e81c | 2007-12-31 16:14:33 +0000 | [diff] [blame] | 62 |    This constant is true if Python was not started with an :option:`-O` option. | 
| Christian Heimes | 5b5e81c | 2007-12-31 16:14:33 +0000 | [diff] [blame] | 63 |    See also the :keyword:`assert` statement. | 
| Christian Heimes | 9bd667a | 2008-01-20 15:14:11 +0000 | [diff] [blame] | 64 |  | 
| Georg Brandl | 0c7ade2 | 2010-08-02 19:39:17 +0000 | [diff] [blame] | 65 |  | 
| Georg Brandl | c589a70 | 2010-08-02 19:36:36 +0000 | [diff] [blame] | 66 | .. note:: | 
 | 67 |  | 
 | 68 |    The names :data:`None`, :data:`False`, :data:`True` and :data:`__debug__` | 
 | 69 |    cannot be reassigned (assignments to them, even as an attribute name, raise | 
 | 70 |    :exc:`SyntaxError`), so they can be considered "true" constants. | 
 | 71 |  | 
| Christian Heimes | 9bd667a | 2008-01-20 15:14:11 +0000 | [diff] [blame] | 72 |  | 
 | 73 | Constants added by the :mod:`site` module | 
 | 74 | ----------------------------------------- | 
 | 75 |  | 
 | 76 | The :mod:`site` module (which is imported automatically during startup, except | 
 | 77 | if the :option:`-S` command-line option is given) adds several constants to the | 
 | 78 | built-in namespace.  They are useful for the interactive interpreter shell and | 
 | 79 | should not be used in programs. | 
 | 80 |  | 
| Georg Brandl | c2a4f4f | 2009-04-10 09:03:43 +0000 | [diff] [blame] | 81 | .. data:: quit(code=None) | 
 | 82 |           exit(code=None) | 
| Christian Heimes | 9bd667a | 2008-01-20 15:14:11 +0000 | [diff] [blame] | 83 |  | 
 | 84 |    Objects that when printed, print a message like "Use quit() or Ctrl-D | 
 | 85 |    (i.e. EOF) to exit", and when called, raise :exc:`SystemExit` with the | 
| Benjamin Peterson | 8719ad5 | 2009-09-11 22:24:02 +0000 | [diff] [blame] | 86 |    specified exit code. | 
| Christian Heimes | 9bd667a | 2008-01-20 15:14:11 +0000 | [diff] [blame] | 87 |  | 
 | 88 | .. data:: copyright | 
 | 89 |           license | 
 | 90 |           credits | 
 | 91 |  | 
 | 92 |    Objects that when printed, print a message like "Type license() to see the | 
 | 93 |    full license text", and when called, display the corresponding text in a | 
 | 94 |    pager-like fashion (one screen at a time). | 
 | 95 |  |