lis中每个项的Python调用函数

2024-09-26 18:16:49 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一组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

有人能帮我解决吗?在


Tags: 函数nametest名称列表isdeffunction

热门问题