blob: 0db83374811d3d9c437624b819b703583305eb66 [file] [log] [blame]
Éric Araujoad84ea12011-07-29 11:53:57 +02001.. _built-in-consts:
2
Georg Brandl8ec7f652007-08-15 14:28:01 +00003Built-in Constants
4==================
5
6A small number of constants live in the built-in namespace. They are:
7
Georg Brandl8ec7f652007-08-15 14:28:01 +00008.. data:: False
9
10 The false value of the :class:`bool` type.
11
12 .. versionadded:: 2.3
13
14
15.. data:: True
16
17 The true value of the :class:`bool` type.
18
19 .. versionadded:: 2.3
20
21
22.. data:: None
23
24 The sole value of :attr:`types.NoneType`. ``None`` is frequently used to
25 represent the absence of a value, as when default arguments are not passed to a
26 function.
27
Georg Brandlb19be572007-12-29 10:57:00 +000028 .. versionchanged:: 2.4
29 Assignments to ``None`` are illegal and raise a :exc:`SyntaxError`.
30
Georg Brandl8ec7f652007-08-15 14:28:01 +000031
32.. data:: NotImplemented
33
34 Special value which can be returned by the "rich comparison" special methods
35 (:meth:`__eq__`, :meth:`__lt__`, and friends), to indicate that the comparison
36 is not implemented with respect to the other type.
37
38
39.. data:: Ellipsis
40
41 Special value used in conjunction with extended slicing syntax.
42
Georg Brandlb19be572007-12-29 10:57:00 +000043
44.. data:: __debug__
45
46 This constant is true if Python was not started with an :option:`-O` option.
Georg Brandl92058d22008-01-20 13:08:37 +000047 See also the :keyword:`assert` statement.
48
49
Georg Brandl1858b6f2010-08-02 20:32:03 +000050.. note::
51
52 The names :data:`None` and :data:`__debug__` cannot be reassigned
53 (assignments to them, even as an attribute name, raise :exc:`SyntaxError`),
54 so they can be considered "true" constants.
55
56 .. versionchanged:: 2.7
57 Assignments to ``__debug__`` as an attribute became illegal.
58
59
Georg Brandl92058d22008-01-20 13:08:37 +000060Constants added by the :mod:`site` module
61-----------------------------------------
62
63The :mod:`site` module (which is imported automatically during startup, except
64if the :option:`-S` command-line option is given) adds several constants to the
65built-in namespace. They are useful for the interactive interpreter shell and
66should not be used in programs.
67
68.. data:: quit([code=None])
69 exit([code=None])
70
71 Objects that when printed, print a message like "Use quit() or Ctrl-D
72 (i.e. EOF) to exit", and when called, raise :exc:`SystemExit` with the
R. David Murraye7ba7422009-08-27 01:04:59 +000073 specified exit code.
Georg Brandl92058d22008-01-20 13:08:37 +000074
75.. data:: copyright
76 license
77 credits
78
79 Objects that when printed, print a message like "Type license() to see the
80 full license text", and when called, display the corresponding text in a
81 pager-like fashion (one screen at a time).