Pivy problem and some other stuff
Marc 'BlackJack' Rintsch
bj_666 at gmx.net
Thu Aug 30 16:03:48 EDT 2007
On Thu, 30 Aug 2007 19:21:47 +0000, azrael wrote:
> And there is anoher question in my mind.
> Is there a way to make a list in python which contains a series of
> functions. I did'n try it. Something like:
Why don't you just try!?
>>>>def a():
>>>> return 1
>
>>>>def b():
>>>> return 2
>
>>>>def c():
>>>> return 3
>
>>>>def d():
>>>> return 4
>
>>>> list=[a(),b(),c(),d()]
>>>> list
> [1,2,3,4]
This isn't a list of functions but a list of results of function calls.
If you want the functions in that list then leave off the parentheses,
because those are the "call operator".
In [55]: def a():
....: return 1
....:
In [56]: def b():
....: return 2
....:
In [57]: funcs = [a, b]
In [58]: funcs
Out[58]: [<function a at 0xb7792e2c>, <function b at 0xb779e1ec>]
In [59]: funcs[0]()
Out[59]: 1
In [60]: funcs[1]()
Out[60]: 2
Ciao,
Marc 'BlackJack' Rintsch
More information about the Python-list
mailing list