Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 1 | Built-in Constants |
| 2 | ================== |
| 3 | |
| 4 | A small number of constants live in the built-in namespace. They are: |
| 5 | |
| 6 | |
Georg Brandl | 96593ed | 2007-09-07 14:15:41 +0000 | [diff] [blame] | 7 | .. note:: |
| 8 | |
| 9 | :data:`None`, :data:`False`, :data:`True` and :data:`__debug__` cannot be |
Georg Brandl | 18a499d | 2007-12-29 10:57:11 +0000 | [diff] [blame] | 10 | reassigned (assignments to them raise :exc:`SyntaxError`), so they can be |
| 11 | considered "true" constants. |
Georg Brandl | 96593ed | 2007-09-07 14:15:41 +0000 | [diff] [blame] | 12 | |
Georg Brandl | 55ac8f0 | 2007-09-01 13:51:09 +0000 | [diff] [blame] | 13 | .. XXX False, True, None are keywords too |
| 14 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 15 | .. data:: False |
| 16 | |
Georg Brandl | 48310cd | 2009-01-03 21:18:54 +0000 | [diff] [blame] | 17 | The false value of the :class:`bool` type. Assignments to ``False`` |
Christian Heimes | 5b5e81c | 2007-12-31 16:14:33 +0000 | [diff] [blame] | 18 | are illegal and raise a :exc:`SyntaxError`. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 19 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 20 | |
| 21 | .. data:: True |
| 22 | |
Georg Brandl | 48310cd | 2009-01-03 21:18:54 +0000 | [diff] [blame] | 23 | The true value of the :class:`bool` type. Assignments to ``True`` |
Christian Heimes | 5b5e81c | 2007-12-31 16:14:33 +0000 | [diff] [blame] | 24 | are illegal and raise a :exc:`SyntaxError`. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 25 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 26 | |
| 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 Heimes | 5b5e81c | 2007-12-31 16:14:33 +0000 | [diff] [blame] | 31 | function. Assignments to ``None`` are illegal and raise a :exc:`SyntaxError`. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 32 | |
| 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 Brandl | cb8ecb1 | 2007-09-04 06:35:14 +0000 | [diff] [blame] | 44 | slicing syntax for user-defined container data types, as in :: |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 45 | |
Christian Heimes | 5b5e81c | 2007-12-31 16:14:33 +0000 | [diff] [blame] | 46 | .. XXX Someone who understands extended slicing should fill in here. |
Georg Brandl | 96593ed | 2007-09-07 14:15:41 +0000 | [diff] [blame] | 47 | |
| 48 | |
| 49 | .. data:: __debug__ |
| 50 | |
Christian Heimes | 5b5e81c | 2007-12-31 16:14:33 +0000 | [diff] [blame] | 51 | 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 Heimes | 9bd667a | 2008-01-20 15:14:11 +0000 | [diff] [blame] | 54 | |
| 55 | |
| 56 | Constants added by the :mod:`site` module |
| 57 | ----------------------------------------- |
| 58 | |
| 59 | The :mod:`site` module (which is imported automatically during startup, except |
| 60 | if the :option:`-S` command-line option is given) adds several constants to the |
| 61 | built-in namespace. They are useful for the interactive interpreter shell and |
| 62 | should not be used in programs. |
| 63 | |
Georg Brandl | c2a4f4f | 2009-04-10 09:03:43 +0000 | [diff] [blame] | 64 | .. data:: quit(code=None) |
| 65 | exit(code=None) |
Christian Heimes | 9bd667a | 2008-01-20 15:14:11 +0000 | [diff] [blame] | 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 | |