Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing multiple arguments to a function?

Tags:

python

I am trying to do an operation like the one below:

a = 2
b = 4
c = 6

def my_function(a,b,c):
    a1 = a*2
    b1 = b*2
    c1 = c*2
    return (a1,b1,c1)

x = my_function(a,b,c)

my_function(x)

Where I would like to call my_function() iteratively on its own output if it meets a certain condition.

However, I get the result:

TypeError: my_function() missing 2 required positional arguments: 'b' and 'c'

I am sure this is a basic question and has been answered elsewhere, but it seems so simple that it is difficult to search for.

like image 709
arachnid_roller_pumpkin Avatar asked Feb 04 '23 08:02

arachnid_roller_pumpkin


1 Answers

use * to Unpack tuple so that all elements of it can be passed as different parameters.

my_function(*x)
like image 191
akash karothiya Avatar answered Feb 06 '23 22:02

akash karothiya