# dict做参数,关键字做参数
d = {'a':1}
def foo(**arg):
print arg, type(arg)
foo(a=1)
foo(**d)
# list tuple 做参数
l = [1,2,3]
t = (1,2,3)
def foo2(*arg):
print arg, type(arg)
foo2(*l)
foo2(*t)
foo2(1,2,3)
#执行结果
{'a': 1} <type 'dict'>
{'a': 1} <type 'dict'>
(1, 2, 3) <type 'tuple'>
(1, 2, 3) <type 'tuple'>
(1, 2, 3) <type 'tuple'>
本文深入探讨了Python中使用*args和**kwargs进行参数传递的方法,包括字典、列表、元组作为参数的处理方式及特性。通过实例演示,帮助读者掌握Python灵活的参数处理技巧。
536

被折叠的 条评论
为什么被折叠?



