I know that *args and **kwargs are ways to feed more arguments into a function in Python.

I am wondering where these terms stem from. Why have all the asterisks in the beginning? What does the kw in kwargs stand for?

  • 1
    What part of docs.python.org/reference/… is confusing? It seems very clear. Can you provide the specific words or phrases that confuse you? – S.Lott Jan 23 '12 at 19:51
  • 1
    @S.Lott What part of the documentation touches on the origin of the notation? – user7043 Jan 23 '12 at 19:52
  • "What does the kw in kwargs stand for?" seems to be quite clearly defined. The "origin" for all of Python is either in a PEP (20%) or in the head of the BDFL (80%). – S.Lott Jan 23 '12 at 19:57
  • @root45: Please post your answer as an answer. – S.Lott Jan 23 '12 at 19:58
  • @S.Lott content update, the page you're linking doesn't mention at any point the string kwargs and only three times args, but in places where it doesn't answers the OP's question – Nino Filiu Apr 14 '19 at 21:04

The "kw" stands for Key Word because the dictionary that you pass in is expanded to a sequence of key-word pair arguments. As to "Why have all the asterisks in the beginning?" I ask you, why not have them?

My hypothesis as to why the * characters were chosen is that they frequently have a wildcard meaning (e.g., in regular expressions or globing). This is just guess-work though and I have nothing to document that.

  • 4
    In C, they mean "pointer to", as in "indirect reference". Maybe that's why they were chosen. – S.Lott Jan 23 '12 at 20:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.