*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

Is their any functions in python to split a string in to a list of strings ?

Fortunately we have split() built-in function in python to split a string in to a list of strings .we can define any separator, anyway default separator is any whitespace. so by default spilt() function split a string in to a list of strings based on any whitespace.

Syntax of split() function in Python

string.split(separator, maxsplit)

separator : It is an optional parameter, if we specify based on the separator value split a string in to a list of strings
maxsplit: It is also optional parameter, it specify how many number of splits to , by default it is all the occurrence.

Usage of split() function in Python

Hello_string = ” Hello, good morning ”

myitem = Hello_string.split(“, “)

print(myitem)

functions in python to split a string in to a list of strings