2
votes

In python3, the help output for sorted, for example, is:

"sorted(iterable, /, *, key=None, reverse=False)"

What does the '/' and '*' mean?

help(sorted)

python2 output is

sorted(iterable, cmp=None, key=None, reverse=False) --> new sorted list

so what is the '/' and '*' in python3?

1

1 Answers

3
votes

/ marks the end of positional-only parameters and the beginning of positional-or-keyword parameters, while * marks the end of positional-or-keyword parameters and the beginning of keyword-only parameters.

In case of the sorted function where the signature is sorted(iterable, /, *, key=None, reverse=False), it means that the iterable parameter can only be specified as a positional argument so you can't call sorted(iterable=some_list), and that the key and reverse parameters can only be specified as keyword arguments, so you can't call sorted(some_list, some_func, True).

Please refer to PEP-0457 for more details.