>>> def argsKwargs(*args, **kwargs):
... print(args)
... print(kwargs)
...
>>> argsKwargs('1', 1, 'slgotting.com', upvote='yes', is_true=True, test=1, sufficient_example=True)
('1', 1, 'slgotting.com')
{'upvote': 'yes', 'is_true': True, 'test': 1, 'sufficient_example': True}
def myFun(*args,**kwargs):
print("args: ", args)
print("kwargs: ", kwargs)
myFun('my','name','is Maheep',firstname="Maheep",lastname="Chaudhary")
# *args - take the any number of argument as values from the user
# **kwargs - take any number of arguments as key as keywords with
# value associated with them
# Python program to illustrate
# **kwargs for variable number of keyword arguments
def info(**kwargs):
for key, value in kwargs.items():
print ("%s == %s" %(key, value))
# Driver code
info(first ='This', mid ='is', last='Me')
def foo(*args):
for a in args:
print(a)
foo(1)
# 1
foo(1,2,3)
# 1
# 2
# 3
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)
kwargs = {"arg1": "Geeks", "arg2": "for", "arg3": "Geeks"}
myFun(**kwargs)