Python – Origin of *args and **kwargs Symbols

python

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?

Best Answer

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.

Related Topic