Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using a tuple as function arguments

Tags:

python

For this function I can use tuple elements as arguments:

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

What if i have 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 does work is

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

which does not really 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?

like image 428
mosaic Avatar asked Aug 14 '26 14:08

mosaic


1 Answers

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

like image 54
Daniel Kluev Avatar answered Aug 16 '26 03:08

Daniel Kluev