Discuss / Python / 第三题,适用于所有字符串转化数字

第三题,适用于所有字符串转化数字

Topic source

def str2float(s): def str2num(s): return {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9}[s] def fn1(x,y): return x10+y c=s.index('.') d=len(s) g=d-c-1 return (reduce(fn1,map(str2num,s[:c])))+pow(10,-g)reduce(fn1,map(str2num,s[c+1:]))

return {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9}[s] 最后面的[s] 是什么意思啊?请问

诚然砰砰

#3 Created at ... [Delete] [Delete and Lock User]

索引 字符串S


  • 1

Reply