Monday, July 26, 2021

*args vs **kwargs in Python

args vs kwargs
In [1]:
def varadd(*x):
       print(type(x))
       print(x)
varadd(5,6)
varadd(6,7,"fggdfg")
<class 'tuple'>
(5, 6)
<class 'tuple'>
(6, 7, 'fggdfg')
In [3]:
def varfun(**y):
       print(type(y))
       print(y)
       print(y)
varfun()
varfun(a=4,b=8,c=9,d="dfgfdg",e=[])
<class 'dict'>
{}
{}
<class 'dict'>
{'a': 4, 'b': 8, 'c': 9, 'd': 'dfgfdg', 'e': []}
{'a': 4, 'b': 8, 'c': 9, 'd': 'dfgfdg', 'e': []}
In [ ]: