首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > perl python >

raw_input()的一个奇怪的用法,该怎么处理

2012-03-26 
raw_input()的一个奇怪的用法1,CSDN raw_input(Enter your Number:)print(CSDN)#*****************#**

raw_input()的一个奇怪的用法
1,CSDN = raw_input('Enter your Number:')
  print(CSDN)
#*****************
#*****************
2,CSDN = raw_input("Enter your Number:")
  print int(CSDN)

 这个 我都敲进:10.125
执行1代码,报Traceback (most recent call last):
执行2代码,出正确结果:10

请问这2者有什么区别,什么情况使用(''),如何又使用(“”)呢?

[解决办法]
从键盘获取的是str类型。(''),和(“”)没有啥区别。


[解决办法]
>>> int('10.5')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 10: '10.5'
>>> int('10')
10

int([x[, base]]) 
Convert a string or number to a plain integer. If the argument is a string, it must contain a possibly signed decimal number representable as a Python integer, possibly embedded in whitespace. 
这段鸟语我没看懂,是不是说需要这个字符串是python integer类型格式?
[解决办法]
转浮点字符串用float()
[解决办法]
解释器报啥错认真看看,看不懂就整个贴出来,不要自言自语...
[解决办法]
I_NBFA 说的对,你输入的字符串 "10.5" 要转换为数字,因为10.5是float,所以用float(CSDN)
[解决办法]
我测试过很多次,都没问题,我的py版本也是2.7,ubuntu内置的

热点排行