Executing a list of functions

7stud bbxx789_05ss at yahoo.com
Fri Mar 16 23:05:44 CET 2007

On Mar 16, 3:59 pm, "7stud" <bbxx789_0... at yahoo.com> wrote:
> lst = [a, b]
> The () symbol causes the named function to execute, and a function
> call in the code is always replaced by the function's return value.

Try this:

def a():
        print "this is a"

def b():
        print "this is b"

lst = [a(), b()]

To create the list, the terms inside the list have to be evaluated.
That causes a and b to execute, and the function calls are replaced by
the each function's return value.  Since your functions don't have a
return statement, the value None is returned.  To see that, add this

print lst

More information about the Python-list mailing list