def a1(a, b)
if a == 1:
return texta
elif b == 1:
return textb
小心别错过任何案子。如果a = 0和b = 0呢?然后这个函数将返回None。你知道吗
最后,我不确定你到底想用这个循环做什么,但也许是这样的?你知道吗
# assign a and b values somewhere
a = 1
b = 0
# save the functions in a list
my_functions = [a1, a2, a3]
# execute each function with the parameters `a` and `b`
for f in my_functions:
result = f(a, b)
x.append(result)
您可以在传递
a
和b
的地方生成lambda,如下所示:您可以这样调用这样的函数:
我不知道你想要什么。这可以存储在字典中,就像我在上面的示例中所做的那样。你知道吗
我可以尝试一下你要去的方向,并提供一定程度的指导,但我怀疑如果没有更多的信息,我不会去正确的方向。你知道吗
首先,不需要
self
作为参数。这只适用于对象。你知道吗接下来,您需要提供函数中使用的变量作为参数。看起来您试图使用
a
和b
而没有声明它们。你知道吗小心别错过任何案子。如果
a = 0
和b = 0
呢?然后这个函数将返回None
。你知道吗最后,我不确定你到底想用这个循环做什么,但也许是这样的?你知道吗
这将产生一个包含函数执行结果的列表,其中包含参数
a
和b
。希望能提供更多帮助,但我们需要更多信息。或许上述情况会刺激这一点。你知道吗相关问题 更多 >
编程相关推荐