1. 程式人生 > >Python 中 apply 內建函式(關鍵詞:Python/內建函式/apply)

Python 中 apply 內建函式(關鍵詞:Python/內建函式/apply)

>>> apply
<built-in function apply>
>>> def a():
...     print 'i am a'
...
>>> apply(a)
i am a
>>> def b():
...     return 1
...
>>> apply(b)
1
>>> def c(x=1):
...     return x + 1
...
>>> apply(c)
2
>>> apply(c, 4)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: apply() arg 2 expected sequence, found int
>>> apply(c, (4,))
5