@@ -767,6 +767,41 @@ Yes. Usually this is done by nesting :keyword:`lambda` within
|
767 | 767 | Don't try this at home, kids! |
768 | 768 | |
769 | 769 | |
| 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 | + |
770 | 805 | Numbers and strings |
771 | 806 | =================== |
772 | 807 | |
|