[Tutor] what does the forward slash mean in this function signature?

eryk sun eryksun at gmail.com
Mon Oct 15 08:10:03 EDT 2018

On Mon, Oct 15, 2018 at 6:00 AM Albert-Jan Roskam
<sjeik_appie at hotmail.com> wrote:
> In Python 3.6 (Windows) I often see a forward slash in a function signature, see below.
> What does it mean? I vaguely remember reading something about new possbilities in
> python 3, something like "def foo(x, *, y)". Perhaps it's related to that?
> >>> help({}.fromkeys)
> Help on built-in function fromkeys:
> fromkeys(iterable, value=None, /) method of builtins.type instance
>     Returns a new dict with keys from iterable and values equal to value.

This syntax is for position-only function parameters. It's used by
Argument Clinic [1], a preprocessor used internally to develop
CPython. Position-only parameters have also been proposed for the
language grammar, first in PEP 457 and again in PEP 570 [2].

[1]: https://docs.python.org/3/howto/clinic.html#converting-your-first-function
[2]: https://www.python.org/dev/peps/pep-0570

More information about the Tutor mailing list