How to extract parameters from a list and pass them to a function call [duplicate]
问题 This question already has an answer here: Use of *args and **kwargs [duplicate] 11 answers What is a good, brief way to extract items from a list and pass them as parameters to a function call, such as in the example below? Example: def add(a,b,c,d,e): print(a,b,c,d,e) x=(1,2,3,4,5) add(magic_function(x)) 回答1: You can unpack a tuple or a list into positional arguments using a star. def add(a, b, c): print(a, b, c) x = (1, 2, 3) add(*x) Similarly, you can use double star to unpack a dict into