python3里函数怎么样使用元组或字典作为参数调用(复制他人博客)

在python3中可以采用如下方法:

        函数(*(元组))

        函数(**{字典})

如下例子:
       function(*("whither", "canada?"))               元组
       function(*(1, 2 + 3))                                   元组
       function(**{"a": "crunchy", "b": "frog"})      字典

 

在python2中,可以使用apply来实现

def function(a, b):
      print a, b
 
apply(function, ("whither", "canada?"))
apply(function, (1, 2 + 3))

posted @ 2018-12-21 22:41  yekang_lucky  阅读(2318)  评论(0编辑  收藏  举报