*args and**kwargs
args
def myFun(*argv):
for arg in argv:
print(arg,end=',')
myFun('Hello', 'Welcome', 'to', 'GeeksforGeeks')
Out: Hello,Welcome,to,GeeksforGeeks
=========================================================
def myFun(arg1, *argv):
print ("First argument :", arg1)
for arg in argv:
print("Next argument through *argv :", arg)
myFun('Hello', 'Welcome', 'to', 'GeeksforGeeks')
Out: First argument : Hello
Next argument through *argv : Welcome
Next argument through *argv : to
Next argument through *argv : GeeksforGeeks
==========================================================
def myFun(arg1, arg2, arg3):
print("arg1:", arg1)
print("arg2:", arg2)
print("arg3:", arg3)
# Now we can use *args or **kwargs to
# pass arguments to this function :
args = ("Geeks", "for", "Geeks")
myFun(*args)
Out: arg1: Geeks
arg2: for
arg3: Geekskwargs
Last updated