blob: 42b5af23a5b9f2a81b3bb22940f8ceddfae5bbe5 [file] [log] [blame]
Éric Araujo96deb752011-06-08 04:53:20 +02001.. _built-in-consts:
2
Georg Brandl116aa622007-08-15 14:28:22 +00003Built-in Constants
4==================
5
6A small number of constants live in the built-in namespace. They are:
7
Georg Brandl116aa622007-08-15 14:28:22 +00008.. data:: False
9
Georg Brandl48310cd2009-01-03 21:18:54 +000010 The false value of the :class:`bool` type. Assignments to ``False``
Christian Heimes5b5e81c2007-12-31 16:14:33 +000011 are illegal and raise a :exc:`SyntaxError`.
Georg Brandl116aa622007-08-15 14:28:22 +000012
Georg Brandl116aa622007-08-15 14:28:22 +000013
14.. data:: True
15
Georg Brandl48310cd2009-01-03 21:18:54 +000016 The true value of the :class:`bool` type. Assignments to ``True``
Christian Heimes5b5e81c2007-12-31 16:14:33 +000017 are illegal and raise a :exc:`SyntaxError`.
Georg Brandl116aa622007-08-15 14:28:22 +000018
Georg Brandl116aa622007-08-15 14:28:22 +000019
20.. data:: None
21
R David Murraye60e12b2012-07-22 20:43:13 -040022 The sole value of the type ``NoneType``. ``None`` is frequently used to
Georg Brandl116aa622007-08-15 14:28:22 +000023 represent the absence of a value, as when default arguments are not passed to a
Christian Heimes5b5e81c2007-12-31 16:14:33 +000024 function. Assignments to ``None`` are illegal and raise a :exc:`SyntaxError`.
Georg Brandl116aa622007-08-15 14:28:22 +000025
26
27.. data:: NotImplemented
28
Ethan Furmanb0049432014-11-26 21:15:35 -080029 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 ``NotImplemented`` is returned, the interpreter will then try the
39 reflected operation on the other type, or some other fallback, depending
40 on the operator. If all attempted operations return ``NotImplemented``, the
41 interpreter will raise an appropriate exception.
42
43 See
44 :ref:`implementing-the-arithmetic-operations`
45 for more details.
46
Georg Brandl116aa622007-08-15 14:28:22 +000047
48
49.. data:: Ellipsis
50
Georg Brandl9499bb72010-08-02 19:35:06 +000051 The same as ``...``. Special value used mostly in conjunction with extended
52 slicing syntax for user-defined container data types.
Georg Brandl96593ed2007-09-07 14:15:41 +000053
54
55.. data:: __debug__
56
Christian Heimes5b5e81c2007-12-31 16:14:33 +000057 This constant is true if Python was not started with an :option:`-O` option.
Christian Heimes5b5e81c2007-12-31 16:14:33 +000058 See also the :keyword:`assert` statement.
Christian Heimes9bd667a2008-01-20 15:14:11 +000059
Georg Brandl0c7ade22010-08-02 19:39:17 +000060
Georg Brandlc589a702010-08-02 19:36:36 +000061.. note::
62
63 The names :data:`None`, :data:`False`, :data:`True` and :data:`__debug__`
64 cannot be reassigned (assignments to them, even as an attribute name, raise
65 :exc:`SyntaxError`), so they can be considered "true" constants.
66
Christian Heimes9bd667a2008-01-20 15:14:11 +000067
68Constants added by the :mod:`site` module
69-----------------------------------------
70
71The :mod:`site` module (which is imported automatically during startup, except
72if the :option:`-S` command-line option is given) adds several constants to the
73built-in namespace. They are useful for the interactive interpreter shell and
74should not be used in programs.
75
Georg Brandlc2a4f4f2009-04-10 09:03:43 +000076.. data:: quit(code=None)
77 exit(code=None)
Christian Heimes9bd667a2008-01-20 15:14:11 +000078
79 Objects that when printed, print a message like "Use quit() or Ctrl-D
80 (i.e. EOF) to exit", and when called, raise :exc:`SystemExit` with the
Benjamin Peterson8719ad52009-09-11 22:24:02 +000081 specified exit code.
Christian Heimes9bd667a2008-01-20 15:14:11 +000082
83.. data:: copyright
84 license
85 credits
86
87 Objects that when printed, print a message like "Type license() to see the
88 full license text", and when called, display the corresponding text in a
89 pager-like fashion (one screen at a time).
90