summaryrefslogtreecommitdiffstats
path: root/Doc/faq/programming.rst
diff options
context:
space:
mode:
authorLysandros Nikolaou <lisandrosnik@gmail.com>2019-03-10 11:30:11 (GMT)
committerNick Coghlan <ncoghlan@gmail.com>2019-03-10 11:30:11 (GMT)
commit1aeeaeb79efa4de41f97b58547e23c2965ecabc5 (patch)
tree1150b1531a70f0df3de6090231b18b0715fbe087 /Doc/faq/programming.rst
parent11205b80309a01666eefee2301a244aa73a4c450 (diff)
downloadcpython-1aeeaeb79efa4de41f97b58547e23c2965ecabc5.zip
cpython-1aeeaeb79efa4de41f97b58547e23c2965ecabc5.tar.gz
cpython-1aeeaeb79efa4de41f97b58547e23c2965ecabc5.tar.bz2
bpo-21314: Add a FAQ entry about positional only parameters (GH-10641)
Diffstat (limited to 'Doc/faq/programming.rst')
-rw-r--r--Doc/faq/programming.rst35
1 files changed, 35 insertions, 0 deletions
diff --git a/Doc/faq/programming.rst b/Doc/faq/programming.rst
index 7bc00ff..3161418 100644
--- a/Doc/faq/programming.rst
+++ b/Doc/faq/programming.rst
@@ -767,6 +767,41 @@ Yes. Usually this is done by nesting :keyword:`lambda` within
Don't try this at home, kids!
+.. _faq-positional-only-arguments:
+
+What does the slash(/) in the parameter list of a function mean?
+----------------------------------------------------------------
+
+A slash in the argument list of a function denotes that the parameters prior to
+it are positional-only. Positional-only parameters are the ones without an
+externally-usable name. Upon calling a function that accepts positional-only
+parameters, arguments are mapped to parameters based solely on their position.
+For example, :func:`pow` is a function that accepts positional-only parameters.
+Its documentation looks like this::
+
+ >>> help(pow)
+ Help on built-in function pow in module builtins:
+
+ pow(x, y, z=None, /)
+ Equivalent to x**y (with two arguments) or x**y % z (with three arguments)
+
+ Some types, such as ints, are able to use a more efficient algorithm when
+ invoked using the three argument form.
+
+The slash at the end of the parameter list means that all three parameters are
+positional-only. Thus, calling :func:`pow` with keyword aguments would lead to
+an error::
+
+ >>> pow(x=3, y=4)
+ Traceback (most recent call last):
+ File "<stdin>", line 1, in <module>
+ TypeError: pow() takes no keyword arguments
+
+Note that as of this writing this is only documentational and no valid syntax
+in Python, although there is :pep:`570`, which proposes a syntax for
+position-only parameters in Python.
+
+
Numbers and strings
===================