from functools import reduce dict_0 = {'0':0,'1':1,'2':2,'3':3,'4':4,'5':5,'6':6,'7':7,'8':8,'9':9} #根据输入的数字取出对应的键值函数 def aa(str): num = dict_0[str] return num strs = input('请输入数字:') rs = list(map(aa,strs)) print(rs) rs = reduce(lambda x,y:x*10+y,rs) print(rs) print(type(rs)) # class Aoti(object): # def aa(self,str): # # self.str = str # figure = dict_0[str] # return figure # def bb(self,x,y): # s = x*10+y # return s # p = Aoti() # rs = list(map(p.aa,'123')) # es = reduce(p.bb,rs) # print(es)
基于python的字符串转整数小程序(手写int()内置函数实现细节)
最新推荐文章于 2023-11-18 16:35:49 发布