Éric Araujo | ad84ea1 | 2011-07-29 11:53:57 +0200 | [diff] [blame] | 1 | .. _built-in-consts: |
| 2 | |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 3 | Built-in Constants |
| 4 | ================== |
| 5 | |
| 6 | A small number of constants live in the built-in namespace. They are: |
| 7 | |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 8 | .. 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 Brandl | b19be57 | 2007-12-29 10:57:00 +0000 | [diff] [blame] | 28 | .. versionchanged:: 2.4 |
| 29 | Assignments to ``None`` are illegal and raise a :exc:`SyntaxError`. |
| 30 | |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 31 | |
| 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 Brandl | b19be57 | 2007-12-29 10:57:00 +0000 | [diff] [blame] | 43 | |
| 44 | .. data:: __debug__ |
| 45 | |
| 46 | 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] | 47 | See also the :keyword:`assert` statement. |
| 48 | |
| 49 | |
Georg Brandl | 1858b6f | 2010-08-02 20:32:03 +0000 | [diff] [blame] | 50 | .. 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 Brandl | 92058d2 | 2008-01-20 13:08:37 +0000 | [diff] [blame] | 60 | Constants added by the :mod:`site` module |
| 61 | ----------------------------------------- |
| 62 | |
| 63 | The :mod:`site` module (which is imported automatically during startup, except |
| 64 | if the :option:`-S` command-line option is given) adds several constants to the |
| 65 | built-in namespace. They are useful for the interactive interpreter shell and |
| 66 | should 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 Murray | e7ba742 | 2009-08-27 01:04:59 +0000 | [diff] [blame] | 73 | specified exit code. |
Georg Brandl | 92058d2 | 2008-01-20 13:08:37 +0000 | [diff] [blame] | 74 | |
| 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). |