Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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?

share|improve this question
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
    
@S.Lott What part of the documentation touches on the origin of the notation? –  delnan 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
    
Thanks, and long live BDFL! –  David Faux Jan 23 '12 at 20:10
add comment

1 Answer

up vote 7 down vote accepted

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.

share|improve this answer
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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