dictionary unpacking
Writing ** before a dictionary in a function call to pass each of its key-value pairs as a keyword argument.
In more detail
template.format(**d) is the same as writing template.format(one=d["one"], two=d["two"]) for every key. The keys must be strings matching the parameter or field names.
Example
"{a}-{b}".format(**{"a": 1, "b": 2})Related terms
- dictionary — A Python collection that stores values under keys, written in curly brackets, such as {"tea": 250}.
- keyword argument — An argument passed by naming the parameter it is for, as in print(x, end=""), instead of by position.
- format method — The string method that returns a copy of a string with each {} replacement field filled in from its arguments.
Taught in
- Dictionaries And String Formatting — Hands-on Python: Complete Video Course & Book
- Exponents, Roots And Float Formats — Hands-on Python: Complete Video Course & Book
- Chapter One In One Sitting — Hands-on Python: Complete Video Course & Book