def add(n1,n2): return n1+n2 def subtr(n1,n2): return n1-n2 def multip(n1,n2): return n1*n2 def divis(n1,n2): return n1/n2 #把操作放入一个字典中 dic = {'+':add,'-':subtr,'*':multip,'/':divis} print(dic.get('+').__name__) #执行打印‘add’ def operator(n1,o,n2): print (dic.get(o)(n1,n2)) operator(2,'*',3)