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 Its truth value is true. 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 ``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. 52 53 54.. data:: Ellipsis 55 56 The same as ``...``. Special value used mostly in conjunction with extended 57 slicing syntax for user-defined container data types. 58 59 60.. data:: __debug__ 61 62 This constant is true if Python was not started with an :option:`-O` option. 63 See also the :keyword:`assert` statement. 64 65 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 72 73Constants added by the :mod:`site` module 74----------------------------------------- 75 76The :mod:`site` module (which is imported automatically during startup, except 77if the :option:`-S` command-line option is given) adds several constants to the 78built-in namespace. They are useful for the interactive interpreter shell and 79should not be used in programs. 80 81.. data:: quit(code=None) 82 exit(code=None) 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 86 specified exit code. 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 96