Commit 981da8c9 authored by scoder's avatar scoder Committed by GitHub

Merge pull request #2261 from gabrieldemarmiesse/keyword_only_arguments

Transfered keyword only arguments.
parents dc0f623a f284a303
......@@ -351,6 +351,36 @@ There may be a slight performance penalty when the optional arg is overridden
with one that does not have default values.
Keyword-only Arguments
----------------------
As in Python 3, ``def`` functions can have keyword-only arguments
listed after a ``"*"`` parameter and before a ``"**"`` parameter if any::
def f(a, b, *args, c, d = 42, e, **kwds):
...
# We cannot call f with less verbosity than this.
foo = f(4, "bar", c=68, e=1.0)
As shown above, the ``c``, ``d`` and ``e`` arguments can not be
passed as positional arguments and must be passed as keyword arguments.
Furthermore, ``c`` and ``e`` are **required** keyword arguments
since they do not have a default value.
A single ``"*"`` without argument name can be used to
terminate the list of positional arguments::
def g(a, b, *, c, d):
...
# We cannot call g with less verbosity than this.
foo = g(4.0, "something", c=68, d="other")
Shown above, the signature takes exactly two positional
parameters and has two required keyword parameters
Error return values
-------------------
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment