我有一组3个函数和一个名称列表。我正在尝试循环这些名称并为每个名称调用一个函数。我的Python看起来像这样。。。在
def testfunc1():
print("This is a test function 1")
#print(name)
def testfunc2():
print("This is a test function 2")
#print(name)
def testfunc3():
print("This is a test function 3")
#print(name)
name_list = ["John", "Joe", "Paul" "George", "Mark", "Craig", "Norman"]
fn_list = [testfunc1(), testfunc2(), testfunc3() ]
for i, name in enumerate(name_list):
[i % len(fn_list)]()
print(name)
我希望这一切发生。。。在
^{pr2}$我对我当前的代码有几个问题,第一个是当前我得到了以下错误。。。在
TypeError: 'list' object is not callable
有人能帮我解决吗?在
实际上,您所做的是用括号(
^{pr2}$[number]()
)包围的“调用一个号码”,您需要首先添加列表引用名称。在输出:
^{3}$相关问题 更多 >
编程相关推荐