python 出现SyntaxError: non-keyword arg after keyword arg错误解决办法
python 出现SyntaxError: non-keyword arg after keyword arg错误解决办法
前言:
在Python中,这两个是python中的可变参数,*arg表示任意多个无名参数,类型为tuple,**kwargs表示关键字参数,为dict,使用时需将*arg放在**kwargs之前,否则会有“SyntaxError: non-keyword arg after keyword arg”的语法错误
def test(*arg,**kwargs): print arg print kwargs print "-------------------" if __name__=='__main__': test(1,2,3,4,5) test(a=1,b=2,c=3) test(1,2,3,a=1,b=3,c=5) output: (1, 2, 3, 4, 5) {} ------------------- () {'a': 1, 'c': 3, 'b': 2} ------------------- (1, 2, 3) {'a': 1, 'c': 5, 'b': 3} -------------------
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
相关推荐
huavhuahua 2020-11-20
weiiron 2020-11-16
cakecc00 2020-11-15
千锋 2020-11-15
JakobHu 2020-11-14
guangcheng 2020-11-13
xirongxudlut 2020-11-10
solarLan 2020-11-09
pythonxuexi 2020-11-08
文山羊 2020-11-07
susmote 2020-11-07
wuShiJingZuo 2020-11-05
Pythonjeff远 2020-11-06
jacktangj 2020-11-04
lousir 2020-11-04
YENCSDN 2020-11-17
lsjweiyi 2020-11-17
houmenghu 2020-11-17
Erick 2020-11-17