个人博客页面链接:http://www.shihao.online/(django搭建的个人博客,还在完善中)

err: 使用input输入时提示变量未定义报错

 #encoding: utf-8
 name =input("Please input your name:\n")
 print("Hello,", name)
Please input your name:
shihao
Traceback (most recent call last): File "用户输入和while循环.py", line 2, in <module> name = input("Please input your name:\n") File "<string>", line 1, in <module> NameError: name 'shihao' is not defined 

把input改为raw_input即可

  #encoding: utf-8
  name =raw_input("Please input your name:\n")
  print("Hello,", name)

区别:
input:会根据用户的输入来做类型的转换
raw_input:则会把用户的输入都作为一个字符串来处理
为了引起不必要的麻烦,推荐使用raw_input