In this lesson, you will learn about kwargs parameters or arguments in python, its syntax with some examples.
Arguments or parameters are values passed to a function inside the parenthesis. A function can have multiple arguments in it, separated by a comma.
We can use special symbols to pass multiple arguments to a function. There are two special symbols:
In this lesson, we are going to see about the non-keyword arguments in python.
**kwargs parameters or arguments are keyword length arguments in python. As we know that a function in python can have an infinite number of arguments for a function, it is important to declare them all. If you are not sure about the number of keyword length arguments, you can use the (*). So when you are not sure about the number of keyword arguments, you can use (*kwargs). This will pass the arguments through the function and will return the result.
Syntax:
def keyword_parameter(**kwargs): statements
Let’s understand more about the **kwargs with the help of a program.
Sample program using the **kwargs in python program
Input:
def kwarg_parameters(**names): print("Welcome to " + names["fname"]+'t' +names['lname']) kwarg_parameters(fname = "Developer Publish Academy!", lname = "Have a Good Day!")
Output:
Welcome to Developer Publish Academy! Have a Good Day!