python中raw_input输入问题

int(100.5)
100
这个对着
int(raw_input('enter the length'))
enter the length100.5

Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
int(raw_input('enter the length'))
ValueError: invalid literal for int() with base 10: '100.5'
为啥这下就不对了?

raw_input得到的是字符串类型。int("100.5")会出错。因为100.5是浮点数不是整数,你可以用float(raw_input('enter the length'))来代替
温馨提示:答案为网友推荐,仅供参考
第1个回答  2015-06-05
raw_input('enter the length')返的是个字符串'100.5'

int()处理不了,只能处理整数形式的字符串。本回答被提问者采纳

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网