What is the asterisk for as "parameter" in Python functions?

Asked

Viewed 52 times

0

I was reading the documentation of version 3.8 of Python, in the part of the new syntax for positional parameters, and found the following function:

def f(a, b, /, c, d, *, e, f):
    print(a, b, c, d, e, f)

In the above function, the parameters a and b are only positional. The other four can be used as keywords.

f(1, 2, 3, d = 4, e = 5, f = 6)

But note that between the parameters, there is a loose asterisk - no parameter. My question is: what is this asterisk? What is it for?

  • @Maniero I think the question is about the "Bare Asterisk" I made that all parameters after the * need named parameters, the questions you put to close the question do not seem to answer that because they speak only of args and kwargs when in fact the doubt refers to the * as a "loose" parameter. Jean, in short the asterisk serves as delimiter, all parameters after it need to be named, and parameters before it are not named.

  • @RFL The second question indicated I think answers, because the answer says: "the function will only receive arguments named after the asterisk. Before that, the arguments may still be positional" etc....

  • @hkotsubo Actually responds. I hadn’t seen her when I searched the site.

  • @RFL Thanks for the help. I only have one question now... how so you "did"? Are you saying that you created this syntax for the language officially? '-'

  • @Jeanextreme002 was typo, I meant "that says everyone..."

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.