Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1aeeaeb

Browse files
lysnikolaouncoghlan
authored andcommitted
bpo-21314: Add a FAQ entry about positional only parameters (GH-10641)
1 parent 11205b8 commit 1aeeaeb

4 files changed

Lines changed: 47 additions & 0 deletions

File tree

Doc/faq/programming.rst

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,41 @@ Yes. Usually this is done by nesting :keyword:`lambda` within
767767
Don't try this at home, kids!
768768

769769

770+
.. _faq-positional-only-arguments:
771+
772+
What does the slash(/) in the parameter list of a function mean?
773+
----------------------------------------------------------------
774+
775+
A slash in the argument list of a function denotes that the parameters prior to
776+
it are positional-only. Positional-only parameters are the ones without an
777+
externally-usable name. Upon calling a function that accepts positional-only
778+
parameters, arguments are mapped to parameters based solely on their position.
779+
For example, :func:`pow` is a function that accepts positional-only parameters.
780+
Its documentation looks like this::
781+
782+
>>> help(pow)
783+
Help on built-in function pow in module builtins:
784+
785+
pow(x, y, z=None, /)
786+
Equivalent to x**y (with two arguments) or x**y % z (with three arguments)
787+
788+
Some types, such as ints, are able to use a more efficient algorithm when
789+
invoked using the three argument form.
790+
791+
The slash at the end of the parameter list means that all three parameters are
792+
positional-only. Thus, calling :func:`pow` with keyword aguments would lead to
793+
an error::
794+
795+
>>> pow(x=3, y=4)
796+
Traceback (most recent call last):
797+
File "<stdin>", line 1, in <module>
798+
TypeError: pow() takes no keyword arguments
799+
800+
Note that as of this writing this is only documentational and no valid syntax
801+
in Python, although there is :pep:`570`, which proposes a syntax for
802+
position-only parameters in Python.
803+
804+
770805
Numbers and strings
771806
===================
772807

Doc/library/functions.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,11 @@ are always available. They are listed here in alphabetical order.
669669
topic, and a help page is printed on the console. If the argument is any other
670670
kind of object, a help page on the object is generated.
671671

672+
Note that if a slash(/) appears in the parameter list of a function, when
673+
invoking :func:`help`, it means that the parameters prior to the slash are
674+
positional-only. For more info, see
675+
:ref:`the FAQ entry on positional-only parameters <faq-positional-only-arguments>`.
676+
672677
This function is added to the built-in namespace by the :mod:`site` module.
673678

674679
.. versionchanged:: 3.4

Doc/library/inspect.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,10 @@ function.
572572
Raises :exc:`ValueError` if no signature can be provided, and
573573
:exc:`TypeError` if that type of object is not supported.
574574

575+
A slash(/) in the signature of a function denotes that the parameters prior
576+
to it are positional-only. For more info, see
577+
:ref:`the FAQ entry on positional-only parameters <faq-positional-only-arguments>`.
578+
575579
.. versionadded:: 3.5
576580
``follow_wrapped`` parameter. Pass ``False`` to get a signature of
577581
``callable`` specifically (``callable.__wrapped__`` will not be used to
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
A new entry was added to the Core Language Section of the Programming FAQ,
2+
which explaines the usage of slash(/) in the signature of a function. Patch
3+
by Lysandros Nikolaou

0 commit comments

Comments
 (0)