*args in python

*args in python is the special syntax used in python to pass n number of argument in a functions.so by using *args we can pass variable-length arguments to a function.

*args in python example

def sum(*argv):
   total=0;
   for num in argv:
       total += num
   return total

print(sum(1, 2, 3, 4, 5)) #output: 15




def sum(*argv):
   total=0;
   for num in argv:
       total += num
   return total

print(sum(1, 2, 3, 4, 5 ,6 ,7,8)) #output: 36

* args in python

My Thought

Your email address will not be published. Required fields are marked *

Our Tool : hike percentage calculator