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?

** 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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.