Discuss / Python / 请教下 哪里错了??

请教下 哪里错了??

Topic source

input() 12.3 '12.3' a=input() 12.3 int(a) Traceback (most recent call last): File "<pyshell#43>", line 1, in <module> int(a) ValueError: invalid literal for int() with base 10: '12.3' a=5.9 int(a) 5 a=input() 1.1 a '1.1' float(a) 1.1 int(a) Traceback (most recent call last): File "<pyshell#49>", line 1, in <module> int(a) ValueError: invalid literal for int() with base 10: '1.1'

float(a)只是float(a)值为1.1, 而a并没有改变,仍然是'1.1' int可以把1.1变为整数,但是不能把'1.1'变为整数。


  • 1

Reply