python selfstudy
python selfstudy
ytkz1 args and kwargs
*args
def test_var_args(f_arg,*v):
print(f_arg)
for arg in v:
print('another arg through *v:', arg)
test_var_args('dd','py','egg')
**kwargs
def func(**k):
for key,value in k.items():
print(key,value)
func(ooo = 'bbb')
use args and kwargs to call function
def test_var_args(a1, a2, a3):
print('arg1:', a1)
print('arg1:', a2)
print('arg1:', a3)
a = ('two', 3, 6)
test_var_args(*a)
def test_var_args(a1, a2, a3):
print('arg1:', a1)
print('arg1:', a2)
print('arg1:', a3)
k = {'a3': 3, 'a2': 6, 'a1': 'ss'}
test_var_args(**k)