0
greens = dict(green="#0080000", olive="#808000", lime="#00FF00")
>>> print("{green} {olive} {lime}".format(**greens))

-> #0080000 #808000 #00FF00

In the program above what are green, olive, and lime in the dict function? I've seen and read about supplying a function with keyword arguments but only when the function was written with default argument. Even then your keyword arguments would have to match the default arguments written in for that function. I don't think dict() has the default args green, olive, and or lime so what am I missing here?

Also, what does **greens do?

2
Contributors
1
Reply
13
Views
3 Years
Discussion Span
Last Post by pyTony
0

** unpacks the dictionary, so the call with **greens is same as writing the arguments as given to dict. Format takes keyword arguments with any names and uses them to replace them in curly brackets in the string.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.