1.. _built-in-consts: 2 3Built-in Constants 4================== 5 6A small number of constants live in the built-in namespace. They are: 7 8.. data:: False 9 10 The false value of the :class:`bool` type. Assignments to ``False`` 11 are illegal and raise a :exc:`SyntaxError`. 12 13 14.. data:: True 15 16 The true value of the :class:`bool` type. Assignments to ``True`` 17 are illegal and raise a :exc:`SyntaxError`. 18 19 20.. data:: None 21 22 The sole value of the type ``NoneType``. ``None`` is frequently used to 23 represent the absence of a value, as when default arguments are not passed to a 24 function. Assignments to ``None`` are illegal and raise a :exc:`SyntaxError`. 25 26 27.. data:: NotImplemented 28 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 It should not be evaluated in a boolean context. 35 36 .. note:: 37 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. 44 45 See :ref:`implementing-the-arithmetic-operations` for examples. 46 47 .. note:: 48 49 ``NotImplementedError`` 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. 52 53 .. versionchanged:: 3.9 54 Evaluating ``NotImplemented`` in a boolean context is deprecated. While 55 it currently evaluates as true, it will emit a :exc:`DeprecationWarning`. 56 It will raise a :exc:`TypeError` in a future version of Python. 57 58 59.. index:: single: ...; ellipsis literal 60.. data:: Ellipsis 61 62 The same as the ellipsis literal "``...``". Special value used mostly in conjunction 63 with extended slicing syntax for user-defined container data types. 64 65 66.. data:: __debug__ 67 68 This constant is true if Python was not started with an :option:`-O` option. 69 See also the :keyword:`assert` statement. 70 71 72.. note:: 73 74 The names :data:`None`, :data:`False`, :data:`True` and :data:`__debug__` 75 cannot be reassigned (assignments to them, even as an attribute name, raise 76 :exc:`SyntaxError`), so they can be considered "true" constants. 77 78 79Constants added by the :mod:`site` module 80----------------------------------------- 81 82The :mod:`site` module (which is imported automatically during startup, except 83if the :option:`-S` command-line option is given) adds several constants to the 84built-in namespace. They are useful for the interactive interpreter shell and 85should not be used in programs. 86 87.. data:: quit(code=None) 88 exit(code=None) 89 90 Objects that when printed, print a message like "Use quit() or Ctrl-D 91 (i.e. EOF) to exit", and when called, raise :exc:`SystemExit` with the 92 specified exit code. 93 94.. data:: copyright 95 credits 96 97 Objects that when printed or called, print the text of copyright or 98 credits, respectively. 99 100.. data:: license 101 102 Object that when printed, prints the message "Type license() to see the 103 full license text", and when called, displays the full license text in a 104 pager-like fashion (one screen at a time). 105