原博客:https://blog.csdn.net/dfq12345/article/details/78074749

Python2.7中内置函数input()会将输入数据当成指令,从键盘中输入数据应该使用raw_input()
在Python3中input()函数用于从键盘中读取数据

  1 #!/usr/bin/python
  2 # -*- coding: utf-8 -*-
  3 
  4 # 使用 input 会出现NameError
  5 message = input("Tell me something, and I will repeat it back to you!\n>")
  6 # message = raw_input("Tell me something, and I will repeat it back to you!\n>")
  7 print(message)
  •  
Tell me something, and I will repeat it back to you!
>Hello
Traceback (most recent call last):
  File "./abc.py", line 5, in <module>
    message = input("Tell me something, and I will repeat it back to you!\n>")
  File "<string>", line 1, in <module>
NameError: name 'Hello' is not defined

 

Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐