*args, **kw是什么意思
*args, **kw是什么意思
*args, **kw是什么意思
2017-11-29
#!/usr/bin/env python
###*args,相当于是一个tuple
def tupleArgs(arg1,arg2='B',*arg3):
print 'arg1=%s'%arg1
print 'arg2=%s'%arg2
for argnum in range(len(arg3)):
print 'the {0} in arg3 :{1}'.format(argnum,arg3[argnum])
###**kw,相当于是一个dict字典
def dictArgs(kw1,kw2='B',**kw3):
print 'kw1={0}'.format(kw1)
print 'kw2={0}'.format(kw2)
for k in kw3:
print 'the {0} in kw3:{1}'.format(k,kw3[k])
if __name__ =='__main__':
tupleArgs('A')
tupleArgs('b','c')
tupleArgs('12','cf','YY','P')
dictArgs('A')
dictArgs('34','k')
dictArgs('kw',c='c',d='123',kw='K')
### kw1=kw kw2=B the c in kw3:c
#the kw in kw3:K
#the d in kw3:123
举报