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