如何调用函数列表并使用字符串列表?
def apple_w():
print(1)
def banana_w():
print(2)
def orange_w():
print(3)
fruits = ['apple','banana','orange']
for i in fruits:
.......
答案 0 :(得分:0)
从你的代码的语法,我猜你使用python。你有globals
- 函数,它返回一个包含所有全局实体的字典。
def apple_w():
print(1)
def banana_w():
print(2)
def orange_w():
print(3)
fruits = ['apple','banana','orange']
for i in fruits:
fn = globals()[i + '_w'] # get the function
fn() # call the function