blob: 89b7d718b41fb674c01d0c3bcf81fb0fa4cb8ff9 [file] [log] [blame]
Georg Brandl116aa622007-08-15 14:28:22 +00001Built-in Constants
2==================
3
4A small number of constants live in the built-in namespace. They are:
5
6
Georg Brandl96593ed2007-09-07 14:15:41 +00007.. note::
8
9 :data:`None`, :data:`False`, :data:`True` and :data:`__debug__` cannot be
Georg Brandl18a499d2007-12-29 10:57:11 +000010 reassigned (assignments to them raise :exc:`SyntaxError`), so they can be
11 considered "true" constants.
Georg Brandl96593ed2007-09-07 14:15:41 +000012
Georg Brandl55ac8f02007-09-01 13:51:09 +000013.. XXX False, True, None are keywords too
14
Georg Brandl116aa622007-08-15 14:28:22 +000015.. data:: False
16
Georg Brandl48310cd2009-01-03 21:18:54 +000017 The false value of the :class:`bool` type. Assignments to ``False``
Christian Heimes5b5e81c2007-12-31 16:14:33 +000018 are illegal and raise a :exc:`SyntaxError`.
Georg Brandl116aa622007-08-15 14:28:22 +000019
Georg Brandl116aa622007-08-15 14:28:22 +000020
21.. data:: True
22
Georg Brandl48310cd2009-01-03 21:18:54 +000023 The true value of the :class:`bool` type. Assignments to ``True``
Christian Heimes5b5e81c2007-12-31 16:14:33 +000024 are illegal and raise a :exc:`SyntaxError`.
Georg Brandl116aa622007-08-15 14:28:22 +000025
Georg Brandl116aa622007-08-15 14:28:22 +000026
27.. data:: None
28
29 The sole value of :attr:`types.NoneType`. ``None`` is frequently used to
30 represent the absence of a value, as when default arguments are not passed to a
Christian Heimes5b5e81c2007-12-31 16:14:33 +000031 function. Assignments to ``None`` are illegal and raise a :exc:`SyntaxError`.
Georg Brandl116aa622007-08-15 14:28:22 +000032
33
34.. data:: NotImplemented
35
36 Special value which can be returned by the "rich comparison" special methods
37 (:meth:`__eq__`, :meth:`__lt__`, and friends), to indicate that the comparison
38 is not implemented with respect to the other type.
39
40
41.. data:: Ellipsis
42
Georg Brandl9499bb72010-08-02 19:35:06 +000043 The same as ``...``. Special value used mostly in conjunction with extended
44 slicing syntax for user-defined container data types.
Georg Brandl96593ed2007-09-07 14:15:41 +000045
46
47.. data:: __debug__
48
Christian Heimes5b5e81c2007-12-31 16:14:33 +000049 This constant is true if Python was not started with an :option:`-O` option.
50 Assignments to :const:`__debug__` are illegal and raise a :exc:`SyntaxError`.
51 See also the :keyword:`assert` statement.
Christian Heimes9bd667a2008-01-20 15:14:11 +000052
53
54Constants added by the :mod:`site` module
55-----------------------------------------
56
57The :mod:`site` module (which is imported automatically during startup, except
58if the :option:`-S` command-line option is given) adds several constants to the
59built-in namespace. They are useful for the interactive interpreter shell and
60should not be used in programs.
61
Georg Brandlc2a4f4f2009-04-10 09:03:43 +000062.. data:: quit(code=None)
63 exit(code=None)
Christian Heimes9bd667a2008-01-20 15:14:11 +000064
65 Objects that when printed, print a message like "Use quit() or Ctrl-D
66 (i.e. EOF) to exit", and when called, raise :exc:`SystemExit` with the
Benjamin Peterson8719ad52009-09-11 22:24:02 +000067 specified exit code.
Christian Heimes9bd667a2008-01-20 15:14:11 +000068
69.. data:: copyright
70 license
71 credits
72
73 Objects that when printed, print a message like "Type license() to see the
74 full license text", and when called, display the corresponding text in a
75 pager-like fashion (one screen at a time).
76