How do I do this in Python? Feature List

def getStuff(x):
    return 'stuff'+x

def getData(x):
    return 'data'+x


thefunctions = []
thefunctions.append("getStuff")
thefunctions.append("getData")

for i in thefunctions:
   print i('abc')

      

Is it possible? Thank.

+2


source to share


1 answer


thefunctions = [ getStuff, getData ]
for f in thefunctions:
    print f('shazam')

      



Once you've made the statement def

, you've associated a name with a function. Just use this name to refer to the function.

+12


source







All Articles