parameters in python built-in functions min() and sorted() -
i'm doing tasks on py.checkio.org, have meet exercise write own function min()
, max()
.
i have read documentation function in official documentation , i'm surprised described parameters, like: min(iterable, *[, key, default])
i'm wondering construction *[,
mean, strange, because *args
, **kwargs
clear, [,arg]
clear. *[,
strange, parameter mean?
p.s sorted() function has strange parameter asterisk: sorted(... *, ...)
can mean?
the following applies python 3 (to op linked).
the single star (*
) in function definition of sorted
denotes following named parameters must supplied keyword arguments ("keyword-only arguments", see pep 3102). means following won't work:
>>> sorted([1, 2, 3], lambda x: x) [...] typeerror: must use keyword argument key function
instead must supply parameters via keyword arguments:
>>> sorted([1, 2, 3], key=lambda x: x) [1, 2, 3]
i'm not sure , *[, key, default]
syntax shall denote (it's not valid python documentation purpose) think developers want express same thing, namely have provide parameters keyword arguments (because min
, max
can take arbitrary number of positional arguments way it).
Comments
Post a Comment