Understanding args and kwargs in Python with an Additional Django Example
<p>When I started learning Python, I was very confused regarding what <code>args</code>, <code>kwargs</code>, <code>*</code> and <code>**</code> 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.</p>
<p><img alt="" src="https://miro.medium.com/v2/resize:fit:700/1*1ILtZ3WOxuI4utO7Yh8Bog.png" style="height:394px; width:700px" /></p>
<p>In Python or any other programming language, we pass some variables or parameters to some function. In this case, these variables are called <strong>arguments</strong> for the function. In the function definition, we must define the type of arguments and the number of arguments we will pass.</p>
<p>But if we do not know the number of arguments we want to pass for any function, we can use the <strong>*args and **kwargs keywords.</strong></p>
<p>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.</p>
<p>Simply put, the functionality of *Args and **Kwargs is summarized as</p>
<blockquote>
<p><strong><em>The *Args and **Kwargs enables a Python programmer to define functions that can accept variable number of arguments.</em></strong></p>
</blockquote>
<p>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.</p>
<p><a href="https://python.plainenglish.io/understanding-args-and-kwargs-in-python-with-an-additional-django-example-fc0eb5313b2d"><strong>Click Here</strong></a></p>