What is the usage of *args and **kwds in python?
Usually i prefer to develop most of my products using a java related technology since i have lots of experience in java. But recently i have to deal with a new project and the project owner specifically asked us to develop that using python. That project was a interesting project to me not only because i have to develop that not using my favourite language but also it was actually a CAD application which we have to develop from the scratch. (Yes, i have done a research over the internet for the other options like similar opensource projects/ even checked whether i could include this as a plugin for famous opensource CAD softwares like FreeCAD. But they all seems to be not good enough solution for the project owners requirements)
Therefore, while i am doing some self learning about python (and all the things related to opengl, pyqt, pyqtgraph) i have came across this *args and **kwds argument in several sample codes.
Basically we can use both *args and **kwds to send variable number of arguments to a function. Note that you can use what ever name for them like *somename and **anothername. Usually eveyone tend to use *args and **kwds as a convention. To get a clear idea see the following example.
def some_function(*args): for arg in args: print("arg =>",arg) some_function("arg1","arg2","arg3")
Output arg => arg1 arg => arg2 arg => arg3
So how different **kwds from *args? Unlike *args , **kwds can be used to send named arguments.
Since there is no point in rewriting examples, take a look at the following blog post for some nice examples and more information.
https://pythontips.com/2013/08/04/args-and-kwargs-in-python-explained/