Why use **kwargs in python? What are some real world advantages over using named arguments?

后端 未结 8 1690
小鲜肉
小鲜肉 2020-12-02 09:52

I come from a background in static languages. Can someone explain (ideally through example) the real world advantages of using **kwargs over named arguments

8条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-02 10:16

    And here's another typical example:

    MESSAGE = "Lo and behold! A message {message!r} came from {object_} with data {data!r}."
    
    def proclaim(object_, message, data):
        print(MESSAGE.format(**locals()))
    

提交回复
热议问题