In this blog, I will cover special args in python
- *args (Non keyword arguments)
- **kwargs (Keyword arguments)
def func1(self,*args):
print(self)
for arg in args:
print (arg)
func1('a','b','c')
def func2(self,**kwargs):
print(self)
for key,value in kwargs:
print(key+'::'+value)
func2('s1',a1='val1',a2='val2',a3='val3',a4='val4')
def func3(self,*args,**kwargs):
print(self)
for arg in args:
print (arg)
for key,value in kwargs:
print(key+'::'+value)
func3('s1',1,2,3,4,a1='val1',a2='val2',a3='val3',a4='val4')
Output:
a
b
c
s1
a::1
a::2
a::3
a::4
s1
1
2
3
4
a::1
a::2
a::3
a::4