如何將存儲爲字符串的負數轉換爲浮點數?Python將字符串轉換爲負數浮動錯誤
我在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'
如何將存儲爲字符串的負數轉換爲浮點數?Python將字符串轉換爲負數浮動錯誤
我在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'模塊來獲取每個字符串的行爲神祕的名字。例如,如果字符串是'''do'import unicodedata as ud''print(* map(ud.name,s),sep =',')'。查看模塊文檔以獲得更多漂亮的功能。當然,你可以執行'print(s.encode('unicode-escape'))' –