python之input(), raw_input()

input(): 要求输入合法的python表达式, 例如字串需要加"", 四则运算会自动计算.

raw_input():所有输入视作字串

>>> val=input("input your expression: ")
input your expression: "what is your name"
>>> print "your input value is: "+val
your input value is: what is your name

>>> val=input("input your expression: ")
input your expression: 3*4+5
>>> print "your input value is: "+str(val)
your input value is: 17

注意: python中的"+"只能连接2个字串,或者作加号. 其它类型必须先转换...否则:

>>> print "your input value is: "+val
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: cannot concatenate 'str' and 'int' objects

posted @ 2016-09-07 12:51  HEZOF  阅读(173)  评论(0编辑  收藏  举报