python appears SyntaxError: non keyword arg after keyword arg error resolution

  • 2020-05-26 09:28:37
  • OfStack

python: non-keyword arg after keyword arg error resolution

Preface:

In Python, these two are the variable parameters in python. *arg means any number of unnamed parameters of type tuple, and **kwargs means the keyword parameter dict. Please put *arg before **kwargs, otherwise there will be a syntax error of "SyntaxError: non-keyword 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}  
-------------------  

Thank you for reading, I hope to help you, thank you for your support of this site!


Related articles: