How python uses kwargs
This article is about how python uses kwargs. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
* * kwargs
There are many milestones when learning any language. Using Python and understanding the mysterious * * kwargs syntax may count as an important milestone.
The double asterisk in front of the dictionary object * * kwargs** allows you to pass the contents of the dictionary to the function as a named argument.
The key to the dictionary is the parameter name, and the value is the value passed to the function. You don't even need to call it kwargs!
Dictionary = {"a": 1, "b": 2} def someFunction (a, b): print (a + b) return# do the same thing: someFunction (* * dictionary) someFunction (axi1, baked 2)
This is useful when you want to write functions that handle named parameters that are not predefined.
Thank you for reading! This is the end of this article on "how python uses kwargs". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!