关于作者

Discuss / Python / 可以直接调用之前的字符串转整型的函数呀

可以直接调用之前的字符串转整型的函数呀

问题来源

天空灬不蓝了

#1 Created at ...

def my_int(s): def fn(x,y): return x*10+y def str_num(s): return {'0':0,'1':1,'2':2,'3':3,'4':4,'5':5,'6':6,'7':7,'8':8,'9':9}[s] return reduce(fn,map(str_num,s))

def my_float(s): if '.' not in s: #对于不带小数点的整数末尾加上'.0' s=s+'.0'
if s[0]=='.': #对于小数点开头的,在开头补'0' s='0'+s
n=s.index('.') #把字符串按小数点分成两段 s1=s[:n] s2=s[n+1:] return my_int(s1)+my_int(s2)10*-len(s2)

天空灬不蓝了

#2 Created at ...

呀,发错位置啦


  • 1

Reply

WARNING: You are using an old browser that does not support HTML5. Please choose a modern browser (Chrome / Microsoft Edge / Firefox / Sarafi) to get a good experience.