Args and kwargs

Args and kwargs stand for arguments, key and word arguments. Actually, the idea behind args and kwargs is that it happens many times when we don’t know how many parameters a function will take then this args and kwargs are very useful.

*Agrs can take any no. of arguments and **kwargs can take any no. of key and value pair i.e, like a dictionary. Let us see through examples.

How to use args and kwargs

Function using *args

Function using **kwargs

Calling a function with multiple arguments

It is opposite to above one in that function definition can take any no. of arguments. Here we are having fixed no. of arguments in function but using multiple inputs(tuple, list) how can we execute a function. If you remember we have discussed zip then it is somewhat similar to that one but not fully.

Hope, you are able to understand the concept of args and kwargs. Though these examples are not much up to the usage of args and kwargs but will try to cover the usage of these concepts in upcoming blogs like in decorators function.

Hope you are enjoying these blogs. Stay tuned! Keep learning with us.

Close Menu