Python学习笔记(三): 收集参数

如下代码:

>>>def print_params(title,*params)
       print title
       print params
>>>print_params('Params:',1,2,3)
      Params:
     (1,2,3)

*的作用是:收集其余的位置参数,返回一个元组,如果不提供任何供收集的元素,params就是个空元组()。

>>>def print_params(title,**params)
       print title
       print params
>>>print_params('Params:',x=1,y=2,z=3)
      Params:
     {'x';1,y'':2,'z':3}

所以,**的作用是:收集其余的位置参数,返回一个字典。

原文地址:https://www.cnblogs.com/hunterCecil/p/5630981.html