Debian Codegraph @

Doc/library/constants.rst

raw
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 An object frequently used to represent the absence of a value, as when
23 default arguments are not passed to a function. Assignments to ``None``
24 are illegal and raise a :exc:`SyntaxError`.
25 ``None`` is the sole instance of the :data:`~types.NoneType` type.
26
27
28 .. data:: NotImplemented
29
30 A special value which should be returned by the binary special methods
31 (e.g. :meth:`~object.__eq__`, :meth:`~object.__lt__`, :meth:`~object.__add__`, :meth:`~object.__rsub__`,
32 etc.) to indicate that the operation is not implemented with respect to
33 the other type; may be returned by the in-place binary special methods
34 (e.g. :meth:`~object.__imul__`, :meth:`~object.__iand__`, etc.) for the same purpose.
35 It should not be evaluated in a boolean context.
36 :data:`!NotImplemented` is the sole instance of the :data:`types.NotImplementedType` type.
37
38 .. note::
39
40 When a binary (or in-place) method returns :data:`!NotImplemented` the
41 interpreter will try the reflected operation on the other type (or some
42 other fallback, depending on the operator). If all attempts return
43 :data:`!NotImplemented`, the interpreter will raise an appropriate exception.
44 Incorrectly returning :data:`!NotImplemented` will result in a misleading
45 error message or the :data:`!NotImplemented` value being returned to Python code.
46
47 See :ref:`implementing-the-arithmetic-operations` for examples.
48
49 .. caution::
50
51 :data:`!NotImplemented` and :exc:`!NotImplementedError` are not
52 interchangeable. This constant should only be used as described
53 above; see :exc:`NotImplementedError` for details on correct usage
54 of the exception.
55
56 .. versionchanged:: 3.9
57 Evaluating :data:`!NotImplemented` in a boolean context was deprecated.
58
59 .. versionchanged:: 3.14
60 Evaluating :data:`!NotImplemented` in a boolean context now raises a :exc:`TypeError`.
61 It previously evaluated to :const:`True` and emitted a :exc:`DeprecationWarning`
62 since Python 3.9.
63
64
65 .. index:: single: ...; ellipsis literal
66 .. data:: Ellipsis
67
68 The same as the ellipsis literal "``...``", an object frequently used to
69 indicate that something is omitted. Assignment to ``Ellipsis`` is possible, but
70 assignment to ``...`` raises a :exc:`SyntaxError`.
71 ``Ellipsis`` is the sole instance of the :data:`types.EllipsisType` type.
72
73
74 .. data:: __debug__
75
76 This constant is true if Python was not started with an :option:`-O` option.
77 See also the :keyword:`assert` statement.
78
79
80 .. note::
81
82 The names :data:`None`, :data:`False`, :data:`True` and :data:`__debug__`
83 cannot be reassigned (assignments to them, even as an attribute name, raise
84 :exc:`SyntaxError`), so they can be considered "true" constants.
85
86
87 .. _site-consts:
88
89 Constants added by the :mod:`site` module
90 -----------------------------------------
91
92 The :mod:`site` module (which is imported automatically during startup, except
93 if the :option:`-S` command-line option is given) adds several constants to the
94 built-in namespace. They are useful for the interactive interpreter shell and
95 should not be used in programs.
96
97 .. data:: quit(code=None)
98 exit(code=None)
99
100 Objects that when printed, print a message like "Use quit() or Ctrl-D
101 (i.e. EOF) to exit", and when accessed directly in the interactive
102 interpreter or called as functions, raise :exc:`SystemExit` with the
103 specified exit code.
104
105 .. data:: help
106 :noindex:
107
108 Object that when printed, prints the message "Type help() for interactive
109 help, or help(object) for help about object.", and when accessed directly
110 in the interactive interpreter, invokes the built-in help system
111 (see :func:`help`).
112
113 .. data:: copyright
114 credits
115
116 Objects that when printed or called, print the text of copyright or
117 credits, respectively.
118
119 .. data:: license
120
121 Object that when printed, prints the message "Type license() to see the
122 full license text", and when called, displays the full license text in a
123 pager-like fashion (one screen at a time).