1 .. _built-in-consts: 2 3 Built-in Constants 4 ================== 5 6 A 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 ``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 54 .. index:: single: ...; ellipsis literal 55 .. data:: Ellipsis 56 57 The same as the ellipsis literal "``...``". Special value used mostly in conjunction 58 with extended slicing syntax for user-defined container data types. 59 60 61 .. data:: __debug__ 62 63 This constant is true if Python was not started with an :option:`-O` option. 64 See also the :keyword:`assert` statement. 65 66 67 .. note:: 68 69 The names :data:`None`, :data:`False`, :data:`True` and :data:`__debug__` 70 cannot be reassigned (assignments to them, even as an attribute name, raise 71 :exc:`SyntaxError`), so they can be considered "true" constants. 72 73 74 Constants added by the :mod:`site` module 75 ----------------------------------------- 76 77 The :mod:`site` module (which is imported automatically during startup, except 78 if the :option:`-S` command-line option is given) adds several constants to the 79 built-in namespace. They are useful for the interactive interpreter shell and 80 should not be used in programs. 81 82 .. data:: quit(code=None) 83 exit(code=None) 84 85 Objects that when printed, print a message like "Use quit() or Ctrl-D 86 (i.e. EOF) to exit", and when called, raise :exc:`SystemExit` with the 87 specified exit code. 88 89 .. data:: copyright 90 credits 91 92 Objects that when printed or called, print the text of copyright or 93 credits, respectively. 94 95 .. data:: license 96 97 Object that when printed, prints the message "Type license() to see the 98 full license text", and when called, displays the full license text in a 99 pager-like fashion (one screen at a time). 100 101