标签:
We often encounter these two parameters.
First *args
This a list of parameters that without name. Baiclly, it is a tuple.
It accepts more than one parameters.
It‘s like Java.
eg in Java:
class HelloWorld(Object ...name): public static void main(String[] args){ System.out.println(name[0].toString()) } }
eg:
def test(*args): for i in args: print i test(1,2,3)
Result: you will get 1 2 3
Second **kwargs keyword
This is a dict with name.
eg:
def kwargs_test(**kwargs): for key, value in kwargs.iteritems(): print "%s = %s" % (key, value) kwargs_test(first_name = "jason", last_name = "zhang")
def kwargs_list_test(**kwargs): print "1--{0}, 2--{1}, 3--{2}".format(a, b, c) par = [‘a‘, ‘b‘, ‘c‘] kwargs_list_test(*par)
标签:
原文地址:http://www.cnblogs.com/-Doraemon/p/4778516.html