Understanding args and kwargs in Python with an Additional Django Example

When I started learning Python, I was very confused regarding what argskwargs* and ** does. And I feel there are many like me who had this confusion and problem. With this post, I intend to reduce (hopefully I can eliminate) that confusion.

In Python or any other programming language, we pass some variables or parameters to some function. In this case, these variables are called arguments for the function. In the function definition, we must define the type of arguments and the number of arguments we will pass.

But if we do not know the number of arguments we want to pass for any function, we can use the *args and **kwargs keywords.

In other language, there is no flexibility to pass the variable number of arguments, but in Python, we can pass the variable number of arguments in a function with the help of *args and **kwargs keywords.

Simply put, the functionality of *Args and **Kwargs is summarized as

The *Args and **Kwargs enables a Python programmer to define functions that can accept variable number of arguments.

Fear not !! if you don’t truly understand the relevance of the above statement. This article is precisely intended to help the reader recognize how *Args and **Kwargs can be useful while defining functions in Python.

Click Here