例如,我试图将173.4k (字符串)转换为173.400。这是我的密码:
h = "173.4k net worth blabla "
match = re.search('([-+]?\d*\.\d+|\d+)k net worth', h)
if match:
f = int(match.group(1))*1000
print(f)
我预期的结果是173.400,但我得到的是:
ValueError: invalid literal for int() with base 10: '173.4'
有人能解释一下为什么我会得到这个ValueError吗?
发布于 2020-09-03 04:12:54
import re
h = "173.4k net worth blabla "
match = re.search('([-+]?\d*\.\d+|\d+)k net worth', h)
if match:
f = float(match.group(1))*1000
print(f)
https://stackoverflow.com/questions/63723266
复制相似问题