kwargs reserved word in python. What does it mean?

This question already has an answer here:

  • What does ** (double star/asterisk) and * (star/asterisk) do for parameters? 15 answers

  • **kwargs means keyword arguments. Its actually not a python keyword, its just a convention, that people follow. That will get all the key-value parameters passed to the function. For example,

    def func(*args, **kwargs):
        print args, kwargs
    func(1, "Welcome", name="thefourtheye", year=2013)
    

    will print

    (1, 'Welcome') {'name': 'thefourtheye', 'year': 2013}
    

    Yes, it means "keyword arguments", but kwargs is not actually a reserved word. It is just the idiomatic thing to call the argument that collects all the unused keyword arguments.

    链接地址: http://www.djcxy.com/p/9058.html

    上一篇: python中的kwargs保留字。 这是什么意思?

    下一篇: python中的kwargs保留字。 这是什么意思?