*args and **kwargs are used to send multiple arguments to a function without changing the function definition
Consider a function foo that accepts four numbers and prints the sum
def foo(a, b, c, d):
sum = a + b + c +d
print("Sum =", sum)
foo(20, 30, 40 ,50)
Using *args:
def foo(*args):
sum = 0
for number in args:
sum = sum + number
print("Sum =", sum)
foo(20, 30, 40 ,50)
Top comments (0)