【发布时间】:2020-01-22 01:34:01
【问题描述】:
如何将存储为字符串的负数转换为浮点数?
在 Python 3.6 上遇到此错误,不知道如何解决。
>>> s = '–1123.04'
>>> float(s)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: could not convert string to float: '–1123.04'
【问题讨论】:
-
FWIW,您可以使用标准的
unicodedata模块来获取字符串中每个行为神秘的字符的名称。例如,如果字符串是s,则执行import unicodedata as udprint(*map(ud.name, s), sep=', ')。有关更多漂亮功能,请参阅模块文档。当然你也可以print(s.encode('unicode-escape'))
标签: python string python-3.x floating-point