码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2018-12-22 01:28:00      阅读:709      评论:0      收藏:0      [点我收藏+]

标签:python2   参数调用   hit   def   app   fun   UNC   nbsp   函数   

在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))

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

标签:python2   参数调用   hit   def   app   fun   UNC   nbsp   函数   

原文地址:https://www.cnblogs.com/yekang/p/10159377.html

(1)
(1)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!