文章目录
- 1 出现原因
- 2 出现的情景
- 3 解决字符串类型的数据转化
1 出现原因
- 使用了
int()
函数 - 且
int()
转化的对象为非数字型字符串
或者浮点型数字字符串
2 出现的情景
- 数字型字符串无法转化
int('1.5')
Traceback (most recent call last):
File "\testPY.py", line 1, in <module>
int('1.5')
ValueError: invalid literal for int() with base 10: '1.5'
- 非法字符报错
int('aaa')
Traceback (most recent call last):
File "\testPY.py", line 1, in <module>
int('aaa')
ValueError: invalid literal for int() with base 10: 'aaa'
3 解决字符串类型的数据转化
print(eval("1.5"))
1.5
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)