blob: 12b56f8893d5c2be6bcf7710163a1422fe8e7a1a [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
Christian Heimes5b5e81c2007-12-31 16:14:33 +000017 The false value of the :class:`bool` type. Assignments to ``False``
18 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
Christian Heimes5b5e81c2007-12-31 16:14:33 +000023 The true value of the :class:`bool` type. Assignments to ``True``
24 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
43 The same as ``...``. Special value used mostly in conjunction with extended
Georg Brandlcb8ecb12007-09-04 06:35:14 +000044 slicing syntax for user-defined container data types, as in ::
Georg Brandl116aa622007-08-15 14:28:22 +000045
Christian Heimes5b5e81c2007-12-31 16:14:33 +000046 .. XXX Someone who understands extended slicing should fill in here.
Georg Brandl96593ed2007-09-07 14:15:41 +000047
48
49.. data:: __debug__
50
Christian Heimes5b5e81c2007-12-31 16:14:33 +000051 This constant is true if Python was not started with an :option:`-O` option.
52 Assignments to :const:`__debug__` are illegal and raise a :exc:`SyntaxError`.
53 See also the :keyword:`assert` statement.
Christian Heimes9bd667a2008-01-20 15:14:11 +000054
55
56Constants added by the :mod:`site` module
57-----------------------------------------
58
59The :mod:`site` module (which is imported automatically during startup, except
60if the :option:`-S` command-line option is given) adds several constants to the
61built-in namespace. They are useful for the interactive interpreter shell and
62should not be used in programs.
63
64.. data:: quit([code=None])
65 exit([code=None])
66
67 Objects that when printed, print a message like "Use quit() or Ctrl-D
68 (i.e. EOF) to exit", and when called, raise :exc:`SystemExit` with the
69 specified exit code, and when .
70
71.. data:: copyright
72 license
73 credits
74
75 Objects that when printed, print a message like "Type license() to see the
76 full license text", and when called, display the corresponding text in a
77 pager-like fashion (one screen at a time).
78