from functools import reduce

def str2float(s):
s = s.split('.')
a = s[0]
b = s[1]
if a[0] == '-':
a = a[1:]
front = reduce(lambda x,y:y+x*10,map(int,a))
a = 0
if 'e' in b:
print('a')
for i in b:
a += 1
if i == 'e':
c = b[a+1:]
middle = reduce(lambda x,y:y+x*10,map(int,c))
b = b[:a-1]
buttom = reduce(lambda x,y:y+x*10,map(int,b))
result = (front + buttom / 10 ** (len(b))) / 10 ** middle
result = -result
print(result)
return result
else:
print('b')
buttom = reduce(lambda x, y: y + x * 10, map(int, b))
result = front + buttom / 10 ** (len(b))
result = -result
print(result)
return result
else :
front = reduce(lambda x, y: y + x * 10, map(int, a))
a = 0
if 'e' in b:
print('c')
for i in b:
a += 1
if i == 'e':
c = b[a+1:]
middle = reduce(lambda x,y:y+x*10,map(int,c))
b = b[:a-1]
buttom = reduce(lambda x,y:y+x*10,map(int,b))
result = (front + buttom / 10 ** (len(b))) / 10 ** middle
print(result)
return result
else:
print('d')
buttom = reduce(lambda x, y: y + x * 10, map(int, b))
result = front + buttom / 10 ** (len(b))
print(result)
return result

  

python:包含’e’和‘-’的 str 转 float的更多相关文章

  1. python附录-builtins.py模块str类源码(含str官方文档链接)

    python附录-builtins.py模块str类源码 str官方文档链接:https://docs.python.org/3/library/stdtypes.html#text-sequence ...

  2. 通俗易懂方式解说Python中repr(变量)和str(变量)函数的区别

    老猿在<Python中repr(变量)和str(变量)的返回值有什么区别和联系>介绍了repr(变量)和str(变量)的区别和联系(对应特殊方法__repr__和__str__),但老猿刚 ...

  3. Python中repr(变量)和str(变量)的返回值有什么区别和联系

    Python中repr(变量)和str(变量)都返回一个描述对象的字符串,二者有关联又有不同.由于Python3.0后都是新式类,我们的分析也是基于新式类进行的.基于object派生的新式类中二者之间 ...

  4. [No000066]python各种类型转换-int,str,char,float,ord,hex,oct等

    int(x [,base ]) #将x转换为一个整数 long(x [,base ]) #将x转换为一个长整数 float(x ) #将x转换到一个浮点数 complex(real [,imag ]) ...

  5. python各种类型转换-int,str,char,float,ord,hex,oct等

    int(x [,base ])         将x转换为一个整数  long(x [,base ])        将x转换为一个长整数  float(x )               将x转换到 ...

  6. 【python】python各种类型转换-int,str,char,float,ord,hex,oct等

    [python] int(x [,base ])         将x转换为一个整数 long(x [,base ])        将x转换为一个长整数 float(x )             ...

  7. python基础复习-1-2 数据类型-str、list、tuple、dict

    数据类型 数字 引号: 123 数值 '123' 字符串 整数:ini long 范围:(-2**31 - 2**31) num = 123 长整型 long (L) num = 123L 浮点型:f ...

  8. python基础之 基本数据类型,str方法和for循环

    1.概念 1.十进制转二进制,对2取余,余数倒序排列 2.字符串为空的时候,bool值为false,字符串非空就是True3.字符串转化成int时,必须是只包含数字才能转化.4.字符串转化成int时可 ...

  9. Python 中的字符串(str)、字典(dict)详解及操作方法

    一.字符串 在python中字符串是一种重要数据类型.其他数据类型分别为: 数字-number -------- int.long.float.complex这几种 字符串-string ------ ...

  10. Python 四种数值类型(int,long,float,complex)区别及转换

    Python支持四种不同的数值类型,包括int(整数)long(长整数)float(浮点实际值)complex (复数), 数字数据类型存储数值.他们是不可改变的数据类型,这意味着改变数字数据类型的结 ...

随机推荐

  1. CentOS7 设置防火墙、开放指定端口操作

    1, 查看防火墙状态: firewall-cmd --state systemctl status firewalld.service 2, 开启防火墙: systemctl start firewa ...

  2. Java基础——IO设计模式总结

  3. 配置代码片段问题 Invalid characters in string. Control characters must be escaped.

    在使用代码片段时报错 Invalid characters in string. Control characters must be escaped. " somethings" ...

  4. uml类间关系总结

    1. 关联关系 (1) 双向关联 顾客购买并拥有商品,商品被顾客购买,Customer和Product双向关联 (2) 单向关联 顾客拥有地址 (3) 自关联:一些类的属性对象类型是本身 (4) 多重 ...

  5. 读《高情商修炼手册》有感 output

    偶然的一次机遇,遇见了这本书,本着情绪的心态的初衷去阅读,没想到还是挺好读的,此次记录是在读完这本书之后的第二天,受output 1.情商高,意味着控制好自己的情绪,让人相处舒服 在智商过剩的年代,有 ...

  6. scrapy中发送post请求

    1.可以使用`yield scrapy.FormRequest(url,formdata,callback)`方法发送POST请求. 其中构造参数formdata可以是字典,也可以是可迭代的(key, ...

  7. UI动画练习 - CABasicAnimation:视图绕X/Y轴旋转(3D效果)

    视图 3D 旋转 1 - 代码示例:以绕 X 轴旋转为例 1 #import "ViewController.h" 2 @interface ViewController () 3 ...

  8. 【git】3.3 git分支-分支管理

    资料来源 (1) https://git-scm.com/book/zh/v2/Git-%E5%88%86%E6%94%AF-%E5%88%86%E6%94%AF%E7%AE%A1%E7%90%86 ...

  9. pytorch的cuda版本安装

    机器上加了RTX3060的卡,cuda装的11.1的版本,cudnn还不是特别清楚装的哪个版本?vs是2017这个版本的.下面来装pytorch.主要参考这个网站的内容"https://bl ...

  10. shopt 内置命令启用shell选项 (extglob)

    使用shopt 内置命令启用shell选项 (extglob) 则会识别几个扩展模式匹配运算符 模式列表是由 | 分割 查看shell选项 extglob shopt |grep extglob 启动 ...