簡體   English   中英

我如何在Python中執行此操作? 列表功能

[英]How do I do this in Python? List to function

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')

這可能嗎? 謝謝。

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

完成def語句后,您將名稱與函數關聯起來。 只需使用該名稱即可引用該功能。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM