2012-06-01 37 views
1

:可以存在需要的参数,如可以有没有指定数量的参数的python函数?

myfunc(a, b, c) 

myfunc(a, b, c, d, e) 

其中两个将工作数目不详蟒蛇的功能呢?

+6

我不会投票,但我建议你的生活会更容易,如果你试图自己解决这些基本问题,并找到你喜欢用来找到这种基本信息的教程/参考。 – Marcin

回答

7

MYFUNC(* ARGS,** KW)

* ARGS - 需要的参数

N多

**千瓦 - 需要字典(未指定深度)

In [1]: def myfunc(*args): 
    ...:  print args 
    ...: 

In [2]: myfunc(1) 
(1,) 

In [3]: myfunc(1,2,3,4,5) 
(1, 2, 3, 4, 5) 
+4

对Python教程的引用在这里很有用,可能类似于:查看关于[定义函数]的Python文档(http://docs.python.org/tutorial/controlflow.html#more-on-defining -功能)。具体请参阅[任意参数列表](http://docs.python.org/tutorial/controlflow.html#arbitrary-argument-lists)和[解包参数列表](http://docs.python.org /tutorial/controlflow.html#unpacking-argument-lists)。 – Chris

相关问题