Note that ``nargs=1`` produces a list of one item. This is different from
the default, in which the item is produced by itself.
+.. index:: single: ? (question mark); in argparse module
+
* ``'?'``. One argument will be consumed from the command line if possible, and
produced as a single item. If no command-line argument is present, the value from
default_ will be produced. Note that for optional arguments, there is an
Namespace(infile=<_io.TextIOWrapper name='<stdin>' encoding='UTF-8'>,
outfile=<_io.TextIOWrapper name='<stdout>' encoding='UTF-8'>)
+.. index:: single: * (asterisk); in argparse module
+
* ``'*'``. All command-line arguments present are gathered into a list. Note that
it generally doesn't make much sense to have more than one positional argument
with ``nargs='*'``, but multiple optional arguments with ``nargs='*'`` is
>>> parser.parse_args('a b --foo x y --bar 1 2'.split())
Namespace(bar=['1', '2'], baz=['a', 'b'], foo=['x', 'y'])
+.. index:: single: + (plus); in argparse module
+
* ``'+'``. Just like ``'*'``, all command-line args present are gathered into a
list. Additionally, an error message will be generated if there wasn't at
least one command-line argument present. For example::
with alternatives (aka "sums"), the left-hand side class is abstract: only
instances of specific constructor nodes are ever created.
+ .. index:: single: ? (question mark); in AST grammar
+ .. index:: single: * (asterisk); in AST grammar
+
.. attribute:: _fields
Each concrete class has an attribute :attr:`_fields` which gives the names
An end-of-file on input is passed back as the string ``'EOF'``.
+ .. index::
+ single: ? (question mark); in a command interpreter
+ single: ! (exclamation); in a command interpreter
+
An interpreter instance will recognize a command name ``foo`` if and only if it
has a method :meth:`do_foo`. As a special case, a line beginning with the
character ``'?'`` is dispatched to the method :meth:`do_help`. As another
The following error handlers are only applicable to
:term:`text encodings <text encoding>`:
+.. index::
+ single: ? (question mark); replacement character
+ single: \ (backslash); escape sequence
+ single: \x; escape sequence
+ single: \u; escape sequence
+ single: \U; escape sequence
+ single: \N; escape sequence
+
+-------------------------+-----------------------------------------------+
| Value | Meaning |
+=========================+===============================================+
interpolation. This means values can be preprocessed before returning them
from ``get()`` calls.
-.. index:: single: %; interpolation in configuration files
+.. index:: single: % (percent); interpolation in configuration files
.. class:: BasicInterpolation()
``%(my_dir)s/Pictures`` as the value of ``my_pictures`` and
``%(home_dir)s/lumberjack`` as the value of ``my_dir``.
-.. index:: single: $; interpolation in configuration files
+.. index:: single: $ (dollar); interpolation in configuration files
.. class:: ExtendedInterpolation()
it returns a string.
+.. index::
+ single: ^ (caret); in curses module
+ single: ! (exclamation); in curses module
+
.. function:: unctrl(c)
Return a string representation of the ASCII character *c*. If *c* is printable,
.. index::
- single: %; datetime format
+ single: % (percent); datetime format
.. _strftime-strptime-behavior:
to test a :exc:`SyntaxError` that omits the traceback header, you will need to
manually add the traceback header line to your test example.
-.. index:: single: ^; caret
+.. index:: single: ^ (caret); marker
* For some :exc:`SyntaxError`\ s, Python displays the character position of the
syntax error, using a ``^`` marker::
.. index::
- single: #; in doctests
- single: +; in doctests
- single: -; in doctests
+ single: # (hash); in doctests
+ single: + (plus); in doctests
+ single: - (minus); in doctests
.. _doctest-directives:
Directives
same as regular expressions (which are documented in the :mod:`re` module). The
special characters used in shell-style wildcards are:
+.. index::
+ single: * (asterisk); in glob-style wildcards
+ single: ? (question mark); in glob-style wildcards
+ single: [] (square brackets); in glob-style wildcards
+ single: ! (exclamation); in glob-style wildcards
+ single: - (minus); in glob-style wildcards
+
+------------+------------------------------------+
| Pattern | Meaning |
+============+====================================+
*domain*, which is returned.
-.. index:: single: _; gettext
+.. index:: single: _ (underscore); gettext
.. function:: gettext(message)
Return the localized translation of *message*, based on the current global
--------------
+.. index::
+ single: * (asterisk); in glob-style wildcards
+ single: ? (question mark); in glob-style wildcards
+ single: [] (square brackets); in glob-style wildcards
+ single: ! (exclamation); in glob-style wildcards
+ single: - (minus); in glob-style wildcards
+ single: . (dot); in glob-style wildcards
+
The :mod:`glob` module finds all the pathnames matching a specified pattern
according to the rules used by the Unix shell, although results are returned in
arbitrary order. No tilde expansion is done, but ``*``, ``?``, and character
:file:`../../Tools/\*/\*.gif`), and can contain shell-style wildcards. Broken
symlinks are included in the results (as in the shell).
+ .. index::
+ single: **; in glob-style wildcards
+
If *recursive* is true, the pattern "``**``" will match any files and zero or
more directories and subdirectories. If the pattern is followed by an
``os.sep``, only directories and subdirectories match.
Accepts a :term:`path-like object`.
-.. index:: single: ~; home directory expansion
+.. index:: single: ~ (tilde); home directory expansion
.. function:: expanduser(path)
Accepts a :term:`path-like object`.
.. index::
- single: $; environment variables expansion
- single: %; environment variables expansion (Windows)
+ single: $ (dollar); environment variables expansion
+ single: % (percent); environment variables expansion (Windows)
.. function:: expandvars(path)
Higher-level operations on pathnames are defined in the :mod:`os.path` module.
-.. index:: single: .; in pathnames
+.. index:: single: . (dot); in pathnames
.. data:: curdir
The constant string used by the operating system to refer to the current
:mod:`os.path`.
-.. index:: single: /; in pathnames
-.. index:: single: \; in pathnames (Windows)
+.. index:: single: / (slash); in pathnames
+.. index:: single: \ (backslash); in pathnames (Windows)
.. data:: sep
The character used by the operating system to separate pathname components.
useful. Also available via :mod:`os.path`.
-.. index:: single: /; in pathnames
+.. index:: single: / (slash); in pathnames
.. data:: altsep
An alternative character used by the operating system to separate pathname
:mod:`os.path`.
-.. index:: single: .; in pathnames
+.. index:: single: . (dot); in pathnames
.. data:: extsep
The character which separates the base filename from the extension; for example,
the ``'.'`` in :file:`os.py`. Also available via :mod:`os.path`.
-.. index:: single: :; path separator (POSIX)
+.. index:: single: : (colon); path separator (POSIX)
+ single: ; (semicolon)
.. data:: pathsep
The character conventionally used by the operating system to separate search
The special characters are:
-.. index:: single: .; in regular expressions
+.. index:: single: . (dot); in regular expressions
``.``
(Dot.) In the default mode, this matches any character except a newline. If
the :const:`DOTALL` flag has been specified, this matches any character
including a newline.
-.. index:: single: ^; in regular expressions
+.. index:: single: ^ (caret); in regular expressions
``^``
(Caret.) Matches the start of the string, and in :const:`MULTILINE` mode also
matches immediately after each newline.
-.. index:: single: $; in regular expressions
+.. index:: single: $ (dollar); in regular expressions
``$``
Matches the end of the string or just before the newline at the end of the
a single ``$`` in ``'foo\n'`` will find two (empty) matches: one just before
the newline, and one at the end of the string.
-.. index:: single: *; in regular expressions
+.. index:: single: * (asterisk); in regular expressions
``*``
Causes the resulting RE to match 0 or more repetitions of the preceding RE, as
many repetitions as are possible. ``ab*`` will match 'a', 'ab', or 'a' followed
by any number of 'b's.
-.. index:: single: +; in regular expressions
+.. index:: single: + (plus); in regular expressions
``+``
Causes the resulting RE to match 1 or more repetitions of the preceding RE.
``ab+`` will match 'a' followed by any non-zero number of 'b's; it will not
match just 'a'.
-.. index:: single: ?; in regular expressions
+.. index:: single: ? (question mark); in regular expressions
``?``
Causes the resulting RE to match 0 or 1 repetitions of the preceding RE.
only ``'<a>'``.
.. index::
- single: {; in regular expressions
- single: }; in regular expressions
+ single: {} (curly brackets); in regular expressions
``{m}``
Specifies that exactly *m* copies of the previous RE should be matched; fewer
6-character string ``'aaaaaa'``, ``a{3,5}`` will match 5 ``'a'`` characters,
while ``a{3,5}?`` will only match 3 characters.
-.. index:: single: \; in regular expressions
+.. index:: single: \ (backslash); in regular expressions
``\``
Either escapes special characters (permitting you to match characters like
raw strings for all but the simplest expressions.
.. index::
- single: [; in regular expressions
- single: ]; in regular expressions
+ single: [] (square brackets); in regular expressions
``[]``
Used to indicate a set of characters. In a set:
* Characters can be listed individually, e.g. ``[amk]`` will match ``'a'``,
``'m'``, or ``'k'``.
- .. index:: single: -; in regular expressions
+ .. index:: single: - (minus); in regular expressions
* Ranges of characters can be indicated by giving two characters and separating
them by a ``'-'``, for example ``[a-z]`` will match any lowercase ASCII letter,
``[(+*)]`` will match any of the literal characters ``'('``, ``'+'``,
``'*'``, or ``')'``.
- .. index:: single: \; in regular expressions
+ .. index:: single: \ (backslash); in regular expressions
* Character classes such as ``\w`` or ``\S`` (defined below) are also accepted
inside a set, although the characters they match depends on whether
:const:`ASCII` or :const:`LOCALE` mode is in force.
- .. index:: single: ^; in regular expressions
+ .. index:: single: ^ (caret); in regular expressions
* Characters that are not within a range can be matched by :dfn:`complementing`
the set. If the first character of the set is ``'^'``, all the characters
:exc:`FutureWarning` is raised if a character set contains constructs
that will change semantically in the future.
-.. index:: single: |; in regular expressions
+.. index:: single: | (vertical bar); in regular expressions
``|``
``A|B``, where *A* and *B* can be arbitrary REs, creates a regular expression that
character class, as in ``[|]``.
.. index::
- single: (; in regular expressions
- single: ); in regular expressions
+ single: () (parentheses); in regular expressions
``(...)``
Matches whatever regular expression is inside the parentheses, and indicates the
resulting RE will match the second character. For example, ``\$`` matches the
character ``'$'``.
-.. index:: single: \; in regular expressions
+.. index:: single: \ (backslash); in regular expressions
``\number``
Matches the contents of the group of the same number. Groups are numbered
.. data:: X
VERBOSE
- .. index:: single: #; in regular expressions
+ .. index:: single: # (hash); in regular expressions
This flag allows you to write regular expressions that look nicer and are
more readable by allowing you to visually separate logical sections of the
searched for site-packages; otherwise they won't.
.. index::
- single: #; comment
+ single: # (hash); comment
statement: import
A path configuration file is a file whose name has the form :file:`{name}.pth`
A :class:`Cursor` instance has the following attributes and methods.
+ .. index:: single: ? (question mark); in SQL statements
+ .. index:: single: : (colon); in SQL statements
+
.. method:: execute(sql[, parameters])
Executes an SQL statement. The SQL statement may be parameterized (i. e.
pair: chaining; comparisons
pair: operator; comparison
operator: ==
- operator: <
+ operator: < (less)
operator: <=
- operator: >
+ operator: > (greater)
operator: >=
operator: !=
operator: is
builtin: int
builtin: float
builtin: complex
- single: operator; +
- single: +; unary operator
- single: +; binary operator
- single: operator; -
- single: -; unary operator
- single: -; binary operator
- operator: *
- operator: /
+ single: operator; + (plus)
+ single: + (plus); unary operator
+ single: + (plus); binary operator
+ single: operator; - (minus)
+ single: - (minus); unary operator
+ single: - (minus); binary operator
+ operator: * (asterisk)
+ operator: / (slash)
operator: //
- operator: %
+ operator: % (percent)
operator: **
Python fully supports mixed arithmetic: when a binary arithmetic operator has
pair: bitwise; operations
pair: shifting; operations
pair: masking; operations
- operator: |
- operator: ^
- operator: &
+ operator: | (vertical bar)
+ operator: ^ (caret)
+ operator: & (ampersand)
operator: <<
operator: >>
- operator: ~
+ operator: ~ (tilde)
Bitwise operations only make sense for integers. The result of bitwise
operations is calculated as though carried out in two's complement with an
single: string; interpolation, printf
single: printf-style formatting
single: sprintf-style formatting
- single: %; printf-style formatting
+ single: % (percent); printf-style formatting
.. note::
#. The ``'%'`` character, which marks the start of the specifier.
.. index::
- single: (; in printf-style formatting
- single: ); in printf-style formatting
+ single: () (parentheses); in printf-style formatting
#. Mapping key (optional), consisting of a parenthesised sequence of characters
(for example, ``(somename)``).
#. Conversion flags (optional), which affect the result of some conversion
types.
-.. index:: single: *; in printf-style formatting
+.. index:: single: * (asterisk); in printf-style formatting
#. Minimum field width (optional). If specified as an ``'*'`` (asterisk), the
actual width is read from the next element of the tuple in *values*, and the
object to convert comes after the minimum field width and optional precision.
-.. index:: single: .; in printf-style formatting
+.. index:: single: . (dot); in printf-style formatting
#. Precision (optional), given as a ``'.'`` (dot) followed by the precision. If
specified as ``'*'`` (an asterisk), the actual precision is read from the next
The conversion flag characters are:
.. index::
- single: #; in printf-style formatting
- single: -; in printf-style formatting
- single: +; in printf-style formatting
+ single: # (hash); in printf-style formatting
+ single: - (minus); in printf-style formatting
+ single: + (plus); in printf-style formatting
single: space; in printf-style formatting
+---------+---------------------------------------------------------------------+
single: bytearray; interpolation
single: printf-style formatting
single: sprintf-style formatting
- single: %; printf-style formatting
+ single: % (percent); printf-style formatting
.. note::
#. The ``'%'`` character, which marks the start of the specifier.
.. index::
- single: (; in printf-style formatting
- single: ); in printf-style formatting
+ single: () (parentheses); in printf-style formatting
#. Mapping key (optional), consisting of a parenthesised sequence of characters
(for example, ``(somename)``).
#. Conversion flags (optional), which affect the result of some conversion
types.
-.. index:: single: *; in printf-style formatting
+.. index:: single: * (asterisk); in printf-style formatting
#. Minimum field width (optional). If specified as an ``'*'`` (asterisk), the
actual width is read from the next element of the tuple in *values*, and the
object to convert comes after the minimum field width and optional precision.
-.. index:: single: .; in printf-style formatting
+.. index:: single: . (dot); in printf-style formatting
#. Precision (optional), given as a ``'.'`` (dot) followed by the precision. If
specified as ``'*'`` (an asterisk), the actual precision is read from the next
The conversion flag characters are:
.. index::
- single: #; in printf-style formatting
- single: -; in printf-style formatting
- single: +; in printf-style formatting
+ single: # (hash); in printf-style formatting
+ single: - (minus); in printf-style formatting
+ single: + (plus); in printf-style formatting
single: space; in printf-style formatting
+---------+---------------------------------------------------------------------+
there are differences.
.. index::
- single: {; in string formatting
- single: }; in string formatting
- single: .; in string formatting
- single: [; in string formatting
- single: ]; in string formatting
- single: !; in string formatting
- single: :; in string formatting
+ single: {} (curly brackets); in string formatting
+ single: . (dot); in string formatting
+ single: [] (square brackets); in string formatting
+ single: ! (exclamation); in string formatting
+ single: : (colon); in string formatting
Format strings contain "replacement fields" surrounded by curly braces ``{}``.
Anything that is not contained in braces is considered literal text, which is
The meaning of the various alignment options is as follows:
.. index::
- single: <; in string formatting
- single: >; in string formatting
- single: =; in string formatting
- single: ^; in string formatting
+ single: < (less); in string formatting
+ single: > (greater); in string formatting
+ single: = (equals); in string formatting
+ single: ^ (caret); in string formatting
+---------+----------------------------------------------------------+
| Option | Meaning |
following:
.. index::
- single: +; in string formatting
- single: -; in string formatting
+ single: + (plus); in string formatting
+ single: - (minus); in string formatting
single: space; in string formatting
+---------+----------------------------------------------------------+
+---------+----------------------------------------------------------+
-.. index:: single: #; in string formatting
+.. index:: single: # (hash); in string formatting
The ``'#'`` option causes the "alternate form" to be used for the
conversion. The alternate form is defined differently for different
only if a digit follows it. In addition, for ``'g'`` and ``'G'``
conversions, trailing zeros are not removed from the result.
-.. index:: single: ,; in string formatting
+.. index:: single: , (comma); in string formatting
The ``','`` option signals the use of a comma for a thousands separator.
For a locale aware separator, use the ``'n'`` integer presentation type
.. versionchanged:: 3.1
Added the ``','`` option (see also :pep:`378`).
-.. index:: single: _; in string formatting
+.. index:: single: _ (underscore); in string formatting
The ``'_'`` option signals the use of an underscore for a thousands
separator for floating point presentation types and for integer
strings for i18n, see the
`flufl.i18n <http://flufli18n.readthedocs.io/en/latest/>`_ package.
-.. index:: single: $; in template strings
+.. index:: single: $ (dollar); in template strings
Template strings support ``$``-based substitutions, using the following rules:
rules used by the C compiler).
.. index::
- single: @; in struct format strings
- single: =; in struct format strings
- single: <; in struct format strings
- single: >; in struct format strings
- single: !; in struct format strings
+ single: @ (at); in struct format strings
+ single: = (equals); in struct format strings
+ single: < (less); in struct format strings
+ single: > (greater); in struct format strings
+ single: ! (exclamation); in struct format strings
Alternatively, the first character of the format string can be used to indicate
the byte order, size and alignment of the packed data, according to the
Notes:
(1)
+ .. index:: single: ? (question mark); in struct format strings
+
The ``'?'`` conversion code corresponds to the :c:type:`_Bool` type defined by
C99. If this type is not available, it is simulated using a :c:type:`char`. In
standard mode, it is always represented by one byte.
``count`` bytes, but that the string returned can never contain more than 255
bytes.
+.. index:: single: ? (question mark); in struct format strings
+
For the ``'?'`` format character, the return value is either :const:`True` or
:const:`False`. When packing, the truth value of the argument object is used.
Either 0 or 1 in the native or standard bool representation will be packed, and
.. index::
- single: %; datetime format
+ single: % (percent); datetime format
.. function:: strftime(format[, t])
.. index::
- single: %; datetime format
+ single: % (percent); datetime format
.. function:: strptime(string[, format])
*classCommand*
denotes which kind of widget to make (a button, a label, a menu...)
+.. index:: single: . (dot); in Tkinter
+
*newPathname*
is the new name for this widget. All names in Tk must be unique. To help
enforce this, widgets in Tk are named with *pathnames*, just like files in a
* it prints the exception *etype* and *value* after the stack trace
- .. index:: single: ^; caret
+ .. index:: single: ^ (caret); marker
* if *type(value)* is :exc:`SyntaxError` and *value* has the appropriate
format, it prints the line where the syntax error occurred with a caret
.. index::
- single: %; environment variables expansion (Windows)
+ single: % (percent); environment variables expansion (Windows)
.. function:: ExpandEnvironmentStrings(str)
.. index::
single: clause
single: suite
- single: ;
+ single: ; (semicolon)
A compound statement consists of one or more 'clauses.' A clause consists of a
header and a 'suite.' The clause headers of a particular compound statement are
statement: if
keyword: elif
keyword: else
- single: :; compound statement
+ single: : (colon); compound statement
The :keyword:`if` statement is used for conditional execution:
keyword: else
pair: loop; statement
keyword: else
- single: :; compound statement
+ single: : (colon); compound statement
The :keyword:`while` statement is used for repeated execution as long as an
expression is true:
keyword: else
pair: target; list
object: sequence
- single: :; compound statement
+ single: : (colon); compound statement
The :keyword:`for` statement is used to iterate over the elements of a sequence
(such as a string, tuple or list) or other iterable object:
keyword: finally
keyword: else
keyword: as
- single: :; compound statement
+ single: : (colon); compound statement
The :keyword:`try` statement specifies exception handlers and/or cleanup code
for a group of statements:
statement: with
keyword: as
single: as; with statement
- single: ,; with statement
- single: :; compound statement
+ single: , (comma); with statement
+ single: : (colon); compound statement
The :keyword:`with` statement is used to wrap the execution of a block with
methods defined by a context manager (see section :ref:`context-managers`).
object: function
pair: function; name
pair: name; binding
- single: (; function definition
- single: ); function definition
- single: ,; parameter list
- single: :; compound statement
+ single: () (parentheses); function definition
+ single: , (comma); parameter list
+ single: : (colon); compound statement
A function definition defines a user-defined function object (see section
:ref:`types`):
only when the function is called. [#]_
.. index::
- single: @; function definition
+ single: @ (at); function definition
A function definition may be wrapped by one or more :term:`decorator` expressions.
Decorator expressions are evaluated when the function is defined, in the scope
.. index::
triple: default; parameter; value
single: argument; function definition
- single: =; function definition
+ single: = (equals); function definition
When one or more :term:`parameters <parameter>` have the form *parameter* ``=``
*expression*, the function is said to have "default parameter values." For a
return penguin
.. index::
- single: *; function definition
+ single: * (asterisk); function definition
single: **; function definition
Function call semantics are described in more detail in section :ref:`calls`. A
.. index::
pair: function; annotations
single: ->; function annotations
- single: :; function annotations
+ single: : (colon); function annotations
Parameters may have annotations of the form "``: expression``" following the
parameter name. Any parameter may have an annotation even those of the form
pair: execution; frame
single: inheritance
single: docstring
- single: (; class definition
- single: ); class definition
- single: ,; expression list
- single: :; compound statement
+ single: () (parentheses); class definition
+ single: , (comma); expression list
+ single: : (colon); compound statement
A class definition defines a class object (see section :ref:`types`):
Class creation can be customized heavily using :ref:`metaclasses <metaclasses>`.
.. index::
- single: @; class definition
+ single: @ (at); class definition
Classes can also be decorated: just like when decorating functions, ::
.. index::
single: metaclass
builtin: type
- single: =; class definition
+ single: = (equals); class definition
By default, classes are constructed using :func:`type`. The class body is
executed in a new namespace and the class name is bound locally to the
.. index::
single: parenthesized form
- single: (; tuple display
- single: ); tuple display
+ single: () (parentheses); tuple display
A parenthesized form is an optional expression list enclosed in parentheses:
.. index::
single: comma; tuple display
pair: tuple; display
- single: ,; tuple display
+ single: , (comma); tuple display
Note that tuples are not formed by the parentheses, but rather by use of the
comma operator. The exception is the empty tuple, for which parentheses *are*
pair: list; comprehensions
pair: empty; list
object: list
- single: [; list expression
- single: ]; list expression
- single: ,; expression list
+ single: [] (square brackets); list expression
+ single: , (comma); expression list
A list display is a possibly empty series of expressions enclosed in square
brackets:
.. index::
pair: set; display
object: set
- single: {; set expression
- single: }; set expression
- single: ,; expression list
+ single: {} (curly brackets); set expression
+ single: , (comma); expression list
A set display is denoted by curly braces and distinguishable from dictionary
displays by the lack of colons separating keys and values:
pair: dictionary; display
key, datum, key/datum pair
object: dictionary
- single: {; dictionary expression
- single: }; dictionary expression
- single: :; in dictionary expressions
- single: ,; in dictionary displays
+ single: {} (curly brackets); dictionary expression
+ single: : (colon); in dictionary expressions
+ single: , (comma); in dictionary displays
A dictionary display is a possibly empty series of key/datum pairs enclosed in
curly braces:
.. index::
pair: generator; expression
object: generator
- single: (; generator expression
- single: ); generator expression
+ single: () (parentheses); generator expression
A generator expression is a compact generator notation in parentheses:
.. index::
pair: attribute; reference
- single: .; attribute reference
+ single: . (dot); attribute reference
An attribute reference is a primary followed by a period and a name:
.. index::
single: subscription
- single: [; subscription
- single: ]; subscription
+ single: [] (square brackets); subscription
.. index::
object: sequence
.. index::
single: slicing
single: slice
- single: :; slicing
- single: ,; slicing
+ single: : (colon); slicing
+ single: , (comma); slicing
.. index::
object: sequence
object: callable
single: call
single: argument; call semantics
- single: (; call
- single: ); call
- single: ,; argument list
- single: =; in function calls
+ single: () (parentheses); call
+ single: , (comma); argument list
+ single: = (equals); in function calls
.. _calls:
there were no excess keyword arguments.
.. index::
- single: *; in function calls
+ single: * (asterisk); in function calls
single: unpacking; in function calls
If the syntax ``*expression`` appears in the function call, ``expression`` must
.. index::
single: negation
single: minus
- single: operator; -
- single: -; unary operator
+ single: operator; - (minus)
+ single: - (minus); unary operator
The unary ``-`` (minus) operator yields the negation of its numeric argument.
.. index::
single: plus
- single: operator; +
- single: +; unary operator
+ single: operator; + (plus)
+ single: + (plus); unary operator
The unary ``+`` (plus) operator yields its numeric argument unchanged.
.. index::
single: inversion
- operator: ~
+ operator: ~ (tilde)
The unary ``~`` (invert) operator yields the bitwise inversion of its integer
argument. The bitwise inversion of ``x`` is defined as ``-(x+1)``. It only
.. index::
single: multiplication
- operator: *
+ operator: * (asterisk)
The ``*`` (multiplication) operator yields the product of its arguments. The
arguments must either both be numbers, or one argument must be an integer and
.. index::
single: matrix multiplication
- operator: @
+ operator: @ (at)
The ``@`` (at) operator is intended to be used for matrix multiplication. No
builtin Python types implement this operator.
.. index::
exception: ZeroDivisionError
single: division
- operator: /
+ operator: / (slash)
operator: //
The ``/`` (division) and ``//`` (floor division) operators yield the quotient of
.. index::
single: modulo
- operator: %
+ operator: % (percent)
The ``%`` (modulo) operator yields the remainder from the division of the first
argument by the second. The numeric arguments are first converted to a common
.. index::
single: addition
- single: operator; +
- single: +; binary operator
+ single: operator; + (plus)
+ single: + (plus); binary operator
The ``+`` (addition) operator yields the sum of its arguments. The arguments
must either both be numbers or both be sequences of the same type. In the
.. index::
single: subtraction
- single: operator; -
- single: -; binary operator
+ single: operator; - (minus)
+ single: - (minus); binary operator
The ``-`` (subtraction) operator yields the difference of its arguments. The
numeric arguments are first converted to a common type.
.. index::
pair: bitwise; and
- operator: &
+ operator: & (ampersand)
The ``&`` operator yields the bitwise AND of its arguments, which must be
integers.
.. index::
pair: bitwise; xor
pair: exclusive; or
- operator: ^
+ operator: ^ (caret)
The ``^`` operator yields the bitwise XOR (exclusive OR) of its arguments, which
must be integers.
.. index::
pair: bitwise; or
pair: inclusive; or
- operator: |
+ operator: | (vertical bar)
The ``|`` operator yields the bitwise (inclusive) OR of its arguments, which
must be integers.
.. index::
single: comparison
pair: C; language
- operator: <
- operator: >
+ operator: < (less)
+ operator: > (greater)
operator: <=
operator: >=
operator: ==
pair: lambda; expression
pair: lambda; form
pair: anonymous; function
- single: :; lambda expression
+ single: : (colon); lambda expression
.. productionlist::
lambda_expr: "lambda" [`parameter_list`] ":" `expression`
.. index::
pair: expression; list
- single: comma; expression list
- single: ,; expression list
+ single: , (comma); expression list
.. productionlist::
expression_list: `expression` ("," `expression`)* [","]
.. index::
pair: iterable; unpacking
- single: *; in expression lists
+ single: * (asterisk); in expression lists
An asterisk ``*`` denotes :dfn:`iterable unpacking`. Its operand must be
an :term:`iterable`. The iterable is expanded into a sequence of items,
--------
.. index:: comment, hash character
- single: #; comment
+ single: # (hash); comment
A comment starts with a hash character (``#``) that is not part of a string
literal, and ends at the end of the physical line. A comment signifies the end
---------------------
.. index:: source character set, encoding declarations (source file)
- single: #; source encoding declaration
+ single: # (hash); source encoding declaration
If a comment in the first or second line of the Python script matches the
regular expression ``coding[=:]\s*([-\w.]+)``, this comment is processed as an
.. index:: string literal, bytes literal, ASCII
- single: '; string literal
- single: "; string literal
+ single: ' (single quote); string literal
+ single: " (double quote); string literal
single: u'; string literal
single: u"; string literal
.. _strings:
"quote" is the character used to open the literal, i.e. either ``'`` or ``"``.)
.. index:: physical line, escape sequence, Standard C, C
- single: \; escape sequence
+ single: \ (backslash); escape sequence
single: \\; escape sequence
single: \a; escape sequence
single: \b; escape sequence
single: string; formatted literal
single: string; interpolated literal
single: f-string
- single: {; in formatted string literal
- single: }; in formatted string literal
- single: !; in formatted string literal
- single: :; in formatted string literal
+ single: {} (curly brackets); in formatted string literal
+ single: ! (exclamation); in formatted string literal
+ single: : (colon); in formatted string literal
.. _f-strings:
Formatted string literals
single: 0b; integer literal
single: 0o; integer literal
single: 0x; integer literal
- single: _; in numeric literal
+ single: _ (underscore); in numeric literal
.. _integers:
.. index::
- single: .; in numeric literal
+ single: . (dot); in numeric literal
single: e; in numeric literal
- single: _; in numeric literal
+ single: _ (underscore); in numeric literal
.. _floating:
Floating point literals
=====================
.. index::
- single: =; assignment statement
+ single: = (equals); assignment statement
pair: assignment; statement
pair: binding; name
pair: rebinding; name
given with the definition of the object types (see section :ref:`types`).
.. index:: triple: target; list; assignment
- single: ,; in target list
- single: *; in assignment target list
- single: [; in assignment target list
- single: ]; in assignment target list
- single: (; in assignment target list
- single: ); in assignment target list
+ single: , (comma); in target list
+ single: * (asterisk); in assignment target list
+ single: [] (square brackets); in assignment target list
+ single: () (parentheses); in assignment target list
Assignment of an object to a target list, optionally enclosed in parentheses or
square brackets, is recursively defined as follows.
.. index::
pair: annotated; assignment
single: statement; assignment, annotated
- single: :; annotated variable
+ single: : (colon); annotated variable
Annotation assignment is the combination, in a single statement,
of a variable or attribute annotation and an optional assignment statement:
.. index::
statement: assert
pair: debugging; assertions
- single: ,; expression list
+ single: , (comma); expression list
Assert statements are a convenient way to insert debugging assertions into a
program:
keyword: from
keyword: as
exception: ImportError
- single: ,; import statement
+ single: , (comma); import statement
.. productionlist::
import_stmt: "import" `module` ["as" `identifier`] ("," `module` ["as" `identifier`])*
from foo.bar import baz # foo.bar.baz imported and bound as baz
from foo import attr # foo imported and foo.attr bound as attr
-.. index:: single: *; import statement
+.. index:: single: * (asterisk); import statement
If the list of identifiers is replaced by a star (``'*'``), all public
names defined in the module are bound in the local namespace for the scope
.. index::
statement: global
triple: global; name; binding
- single: ,; identifier list
+ single: , (comma); identifier list
.. productionlist::
global_stmt: "global" `identifier` ("," `identifier`)*
=================================
.. index:: statement: nonlocal
- single: ,; identifier list
+ single: , (comma); identifier list
.. productionlist::
nonlocal_stmt: "nonlocal" `identifier` ("," `identifier`)*
------------------------
.. index::
- single: *; in function calls
+ single: * (asterisk); in function calls
Finally, the least frequently used option is to specify that a function can be
called with an arbitrary number of arguments. These arguments will be wrapped
.. index::
pair: function; annotations
single: ->; function annotations
- single: :; function annotations
+ single: : (colon); function annotations
:ref:`Function annotations <function>` are completely optional metadata
information about the types used by user-defined functions (see :pep:`3107` and
line by itself in an example means you must type a blank line; this is used to
end a multi-line command.
-.. index:: single: #; comment
+.. index:: single: # (hash); comment
Many of the examples in this manual, even those entered at the interactive
prompt, include comments. Comments in Python start with the hash character,