5、Python3打印函数名之__name__属性

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)        

 

posted @ 2020-09-07 14:04  Real丶  阅读(732)  评论(0编辑  收藏  举报