python - 我如何在 Python 中执行此操作?列表功能

标签 python

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 语句后,您就将名称与函数相关联了。只需使用该名称来引用该函数即可。

关于python - 我如何在 Python 中执行此操作?列表功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1523348/

相关文章:

Python - 使用交互式 CLI 过滤列表

python - 根据输入,在列表上使用 tuple() 不会返回相同的元组

python - 按索引将数据帧合并到列表中

python - 使用SSH中的SSH ProxyCommand的SFTP

python - Jupyter:JupyterLab 在哪里存储用户设置?

python - 为什么函数运行时不带参数?

python - 如何检查列表列表中的所有元素是否都是字符串

Python azure-identity ClientSecretCredential

python - 创建空列表并进行一些操作

python - 如何在 scikit-learn 下绘制拟合高斯混合模型的概率密度函数?