简体   繁体   中英

Passing multiple arguments to a function?

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.

使用*来解包元组,以便它的所有元素都可以作为不同的参数传递。

my_function(*x)

Use the "star args" syntax.

my_function(*x)

See this post for more.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM