*argsand**kwargsare special syntaxes that allow a function to accept a variable number of arguments.You use them when you don't know, how many inputs a user might pass into the function
*args(Positional Arguments Bucket): Collects any number of extra positional arguments into a tuple.**kwargs(Keyword Arguments Bucket): Collects any number of extra keyword (named) arguments into a dictionary (where keys are argument names and values are the values).
# Ex1:
def multiply_numbers(*args):
# 'args' inside the function is a tuple: (2, 3, 4)
result = 1
for num in args:
result *= num
return result
print(multiply_numbers(2, 3, 4)) # Output: 24
# Ex2:
def print_details(**kwargs):
for key, value in kwargs.items():
print(f"{key}: {value}")
print_details(name="Alice", age=25)
# Output:
# name: Alice
# age: 25