2

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 Answer 1

3

/ 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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.