首页 > 转换一个字符串为浮点数会报错 float('‐525050.87')

转换一个字符串为浮点数会报错 float('‐525050.87')

float('‐525050.87')

ValueError: could not convert string to float: ‐525050.87


在我回答你之前, 讓我先問個更奇怪的問題先:

In [60]: '‐' == '-'
Out[60]: False

WHY ?????

讓我來告訴你為什麼, 這就是真相:

en dash

重點在這裡:

An en dash or en rule (–) is wider than a hyphen (-) and narrower than an em dash (–).

舉一要能反三, 我再問個問題:

>>> float('-553l.4')
ValueError: could not convert string to float: '-553l.4'

這題比較簡單, 相信你也知道原因了...


我回答過的問題: Python-QA


预计是将半角的"-"输错为全角了

【热门文章】
【热门文章】