Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Gwenaël Samain
cython
Commits
981da8c9
Commit
981da8c9
authored
May 15, 2018
by
scoder
Committed by
GitHub
May 15, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2261 from gabrieldemarmiesse/keyword_only_arguments
Transfered keyword only arguments.
parents
dc0f623a
f284a303
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
0 deletions
+30
-0
docs/src/userguide/language_basics.rst
docs/src/userguide/language_basics.rst
+30
-0
No files found.
docs/src/userguide/language_basics.rst
View file @
981da8c9
...
...
@@ -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
-------------------
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment