[Tutor] What is meaning of "/" in "pow(x, y, z=None, /)"?

Mats Wichmann mats at wichmann.us
Wed Aug 2 07:59:25 EDT 2017


On 08/01/2017 07:14 PM, Ben Finney wrote:
> boB Stepp <robertvstepp at gmail.com> writes:
> 
>> A quick scan of some of my Python books does not turn up the use of
>> "/" as a function argument.
> 
> The appearance of this in Python's documentation and dfunction signature
> descriptions, without a clear description of what it means, is
> troubling.
> 
> The best I can find is this informational draft PEP
> <URL:https://www.python.org/dev/peps/pep-0457/>, which *proposes* it as
> syntax for some future Python.
> 

Yes, this is kind of interesting.

So it looks like it has been introduced internally to help with
introspection, but has not been introduced in documentation.

Old Python did this:

>>> help(pow)
pow(...)
    pow(x, y[, z]) -> number

new Python does this:

>>> pow(x, y, z=None, /)


Documentation still says this:

 pow(x, y[, z])

While the PEP suggested standardizing on not only the
end-of-positional-only parameters marker but also on the brackets to
show optional positional-only parameters, apparently the implementation
has not done the latter and has instead undone the brackets (at least in
this example) and gone to a different syntax which looks like a keyword
parameter but which you can infer is not because of the presence of the
marker somewhere to its right.


Fine.

So now it looks like the old advice of "if in doubt, ask Python itself"
should be tempered with "... although the response may use syntax that
is not documented anywhere and might confuse you"

Sorry, bad night, I shouldn't be sniping but it's hard to resist.


More information about the Tutor mailing list