In this tutorial we are going to learn :

• Number Of Arguments
• Keyword Arguments
• Default Arguments
• Arbitrary Arguments – xargs
• Arbitrary Keyword Arguments – xxargs

### Number Of Arguments

In our other programs, we used just one parameter. Now we are going to work on arguments in detail.

Example:

This program is an example of passing two-parameter and works with them.

``````def addition(first_number, second_number):
return first_number + second_number

### Keyword Arguments

We can also use keyword arguments to pass parameters with key = value syntax.

Example :

The syntax of the keyword argument is key = value .

``````def addition(first_number, second_number):
return first_number + second_number

### Default Argument

We can also call the function without arguments. This is called default argument. Let’s look
at the example below.

Example :

``````def addition(first_number, second_number = 3):     # default argument
return first_number + second_number

### Arbitrary Arguments – xargs

If we don’t know how many arguments we pass to our function, we can use arbitrary arguments. We use * before the parameter name in the function definition.

Example :

In our addition function, as you can see we used arbitrary argument using * .

``````def addition(*numbers):
last = 0
for x in numbers:
last += x

return last

### Arbitrary Keyword Arguments – xxargs

If we don’t know how many keyword arguments we pass to our function, we can use arbitrary keyword arguments. We use ** before the parameter name in the function
definition.

Example :

``````def person(**intro):    # arbitrary keyword arguments
print(intro)

person(name="John", age=23, status="Student") ``````

• To print our keyword arguments :
``````def person(**intro):    # arbitrary keyword arguments
print(intro["name"])

person(name="John", age=23, status="Student") ``````
0 0 vote
Article Rating
Subscribe
Notify of