Using a tuple as function arguments

For this function, I can use the elements of the set as arguments:

light_blue = .6, .8, .9
gradient.add_color_rgb(0, *light_blue)

What if I need to add another argument after the tuple?

light_blue = .6, .8, .9
alpha = .5
gradient.add_color_rgba(0, *light_blue, alpha)

does not work. What works

gradient.add_color_rgba(0, *list(light_blue)+[alpha])

which doesn't look better than

gradient.add_color_rgba(0, light_blue[0], light_blue[1], light_blue[2], alpha)

Is there a better way to do this?

+3
source share
2 answers

You can call it like gradient.add_color_rgba(0, *light_blue, alpha=alpha)if you know the parameter name for alpha.

+6
source

You can simplify the expression slightly by creating a tuple instead list, containing light_blueand alphafor example.

gradient.add_color_rgba(0, *(light_blue + (alpha,)))
+2
source

Source: https://habr.com/ru/post/1757452/


All Articles