2.5.1.5 Arbitrary Arguments
Python Programming
Sometimes, you might not know how many arguments will be passed to your function. You can use *args and **kwargs to handle such cases.
Example: Define a function to add an arbitrary number of arguments.
python
def add_numbers(*args):
return sum(args) # sum( ) is a python function used to add the values of given arguments
print(add_numbers(1, 2, 3)) # Output : 6
print(add_numbers(4, 5)) # Output : 9Explanation: In this example, the add_numbers function takes a variable number of arguments using *args and returns their sum.