python学习笔记之浮点数字符串转化为整数时报错
调用int()函数转整型时,报错如下: >>> int('1.25') Traceback (most recent call last): File "<pyshell#42>", line 1, in <module> int('1.25') ValueError: invalid literal for int() with base 10: '1.25' 原因: ‘1.25’ 为浮点数字符串,不能求值为整型 正确使用方法,直接浮点数型转整型,或者先转浮点数型后转整型 >>> int(float('1.25')) 1 >>> int(1.25) 1 来源: https://www.cnblogs.com/dulilearn/p/11759026.html