Behaviour of raw_input()

筅森魡賤 提交于 2019-11-27 02:16:52
zhangyangyu

raw_input returns a string. So use int(raw_input()).

And for how string and int comparsions work, look here.

cdent

See the answer here.

Basically you're comparing apples and oranges.

>>> type(0) < type('10')
True
>>> 0 < '10'
True
>>> type(0) ; type('10')
<type 'int'>
<type 'str'>
Python 2.7:    
num = int(raw_input('enter a number:'))
Variable "num" will be of type str if raw_input is used.
type(num)>>str
or 
num = input("Enter a Number:")# only accept int values
type(num)>>int

Python 3.4 : 
num = input("Enter a Number:") will work ...
type(num)>>str
convert the variable "num" to int type(conversion can be done at time of  getting the user "input") :
num1 = int(num)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!