Python-使用列表作为函数参数


Answers:



57

这已经得到了完美的答案,但是由于我刚进入本页并且不立即理解,所以我将添加一个简单但完整的示例。

def some_func(a_char, a_float, a_something):
    print a_char

params = ['a', 3.4, None]
some_func(*params)

>> a

13

使用星号:

some_func(*params)

5
按照这些原则,您还可以使用字典:def f(a,b,c):#do东西。mydict = {'a':1,'b':2,'c':3} f(** mydict)
inspectorG4dget

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.