xxxxxxxxxx
def display(**kwargs):
d = {k.upper():v.upper() for k,v in kwargs.items() }
return d
d = {"name":"neo","age":"33","city":"tokyo"}
print(display(**d))
xxxxxxxxxx
>>> 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}
xxxxxxxxxx
############################# ARGS ###########################################
def my_function(*kids):
print(kids)
print("The youngest child is " + kids[2])
my_function("Emil", "Tobias", "Linus")
>>>('Emil', 'Tobias', 'Linus')
The youngest child is Linus
############################# KWARGS #########################################
def my_function(**kid):
print(kid)
print("His last name is " + kid["lname"])
my_function(fname = "Tobias", lname = "Refsnes")
>>>{'fname': 'Tobias', 'lname': 'Refsnes'}
His last name is Refsnes
xxxxxxxxxx
# 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')
xxxxxxxxxx
def foo(*args):
for a in args:
print(a)
foo(1)
# 1
foo(1,2,3)
# 1
# 2
# 3
xxxxxxxxxx
# Python program to illustrate
# *kwargs for variable number of keyword arguments
def myFun(**kwargs):
for key, value in kwargs.items():
print ("%s == %s" %(key, value))
# Driver code
myFun(first ='Geeks', mid ='for', last='Geeks')
''' output:
last == Geeks
mid == for
first == Geeks
'''
xxxxxxxxxx
def tester(**kwargs):
for key, value in kwargs.items():
print(key, value, end = " ")
tester(Sunday = 1, Monday = 2, Tuesday = 3, Wednesday = 4)
xxxxxxxxxx
def myFun(arg1, **kwargs):
for key, value in kwargs.items():
print("%s == %s" % (key, value))
# Driver code
myFun("Hi", first='Geeks', mid='for', last='Geeks')
xxxxxxxxxx
def myFun(**kwargs):
for key, value in kwargs.items():
print("%s == %s" % (key, value))
# Driver code
myFun(first='Geeks', mid='for', last='Geeks')
xxxxxxxxxx
def display2(a,b,c):
print("kwarg1:", a)
print("kwarg2:", b)
print("kwarg3:", c)
d = {"a": 1, "b": 2, "c": 3}
display2(**d)