Iliass Mw
Iliass Mw

Reputation: 69

Python: Pass array as separate arguments to function

I have a function that I can not edit, this function expects 3 arguments

def rgb_color(r,g,b):
    print(r,g,b)

now I have these values as an array, I can change this var if needed to a list or something

black = [0, 0, 0]

Is there a way to pass the variable black to the function without using

black[0], black[1], black[2]

something like

call_user_function(rgb_color, black) 

Upvotes: 3

Views: 2546

Answers (1)

Aplet123
Aplet123

Reputation: 35512

You can use argument unpacking:

rgb_color(*black)

Upvotes: 9

Related Questions