Procedure:
def method(a,*b,**c): #b is a list while c is a dictionary element
print a
print b
for (key, value) in c.items():
print "%s = %s" %(key,value)
Call:
method(1,2,3,4,5,x='Linux',y='XP')
output:
1 ###a
(2, 3, 4, 5) ###b
y = XP ###c, And the order of elements in C is not fixed yet.
x = Linux
Make sure the key should not be quoted. If call the method in this way:
method(1,2,3,4,5,'x'='Linux','y'='XP')
This error message will show up:
SyntaxError: keyword can't be an expression
本文介绍了一个Python示例函数,该函数使用不同类型的参数:位置参数、可变参数和关键字参数。通过具体实例展示了如何调用函数,并解释了关键字参数在传递时的注意事项。
1755

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



