args Parameters in Python
In this lesson, you will learn about args parameters in python with some examples.
Arguments in Python
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:
- *args (Non-Keyword Arguments)
- **kwargs (Keyword Arguments)
In this lesson, we are going to see about the non-keyword arguments in python.
args Parameters in Python
*args parameters or arguments are non-keyword 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 arguments, you can use the (*). So when you are not sure about the number of non-keyword arguments, you can use (*args).
Syntax:
def nonkeyword_parameter(*args): statements
Let’s understand more about the *args with the help of a program.
Sample program using the *args in python program
Input:
[gamipress_button label=”Try It” onclick=”window.open(‘https://coderseditor.com/?id=1400′,’_blank’)”]
def args_paramters(*num): mul=1 for i in num: mul = mul*i print("Multiplication:",mul) args_paramters(5,7) args_paramters(7,5,6,5) args_paramters(57,75,76,67,6757)
Output:
Multiplication: 35 Multiplication: 1050 Multiplication: 147088403100