Agi*_*gle 1 python int type-conversion
假设我有一个字符串:
temp = "0.1"
Run Code Online (Sandbox Code Playgroud)
当我跑int(temp):
我收到以下错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 10: '0.1'
Run Code Online (Sandbox Code Playgroud)
但是当我跑步时int(float(temp)):
我得到正确的输出即 0
为什么转换float然后转换为int工作但直接转换为int不工作?
感谢致敬