How to call a function by its name as a string in Python

1 Answer

0 votes
def mul(a, b):
   return a * b
 
function_name = "mul"

result = eval(function_name + "(8, 9)")

print(result)
   
   
   
'''
run:
   
72
   
'''

 



answered Jun 6, 2021 by avibootz

Related questions

2 answers 177 views
2 answers 303 views
303 views asked Aug 30, 2017 by avibootz
1 answer 193 views
...