[root@localhost ~]# python test.py
请输入qwer
Traceback (most recent call last):
  File "test.py", line 3, in
    a = input('请输入')
  File "", line 1, in
NameError: name 'qwer' is not defined

test.py文件内容如下
[root@localhost ~]# cat test.py
#!/usr/bin/python
#-*- coding:utf-8 -*-
a = input('请输入')
print(a)
[root@localhost ~]#

(1)出现上面的错误原因是:input()函数,
针对python2.7.5
input它会根据用户输入变换相应的类型,而且如果要输入字符和字符串的时候必须要用引号包起来,而raw_input则是不管用户输入什么类型的都会转变成字符型.


10-04 15:13