python屏幕的交互(读取输出信息)input,raw_input的区别

>>> input("your name?")
your name?sam

Traceback (most recent call last):
  File "<pyshell#0>", line 1, in <module>
    input("your name?")
  File "<string>", line 1, in <module>
NameError: name 'sam' is not defined

可以看到,input函数必须使用字符串作为输出类型,即输出时加双引号引入。如下

>>> input("your name?")
your name?"sam"
'sam'

如果,觉得双引号麻烦,则raw_input(“sting”)可以直接输入,不用双引号:

>>> raw_input("your name?")
your name?sam
'sam'

不带双引号,也没有像input语句那样出错,这就是input与raw_input语句的区别。

posted on 2013-10-28 11:32  代码王子  阅读(263)  评论(0编辑  收藏  举报

导航