In this blog, we will be learning about the args and kwargs functions in python for data science.
*args :- This is a special syntax in function definitions. It is useful for passing a non-keyword variable length of argument list. Here are some of the important attributes of *args.
- The symbol * is there to take in variable number of arguments. It is generally written with the word args.
- *args allows to take in more arguments than the formal arguments. The *args function is helpful in tacking any number of extra arguments on the current formal parameters (zero extra can also be tack).
- When * is there with a variable then, it gets an iterable meaning, we can perform things like run higher-order functions such as maps and filters, iterate over it, etc.
**kwargs :- It is a special syntax for passing a keyword, variable length-argument list. The function kwargs is written with double stars because it allows passing through keyword arguments. Below are some important points.
- Keyword argument is there for providing a name to the variable as we pass it into a function.
- Kwargs can be thought of as a dictionary that keeps maps each keyword to the value pass alongside it. This is the reason when we iterate over the kwargs; there is no specific order in which they get print..
Calling a function using *args and **kwargs: