任何人都可以确认为什么在Python 2.6中返回错误的原因如下?这是3.0语法吗?

时间:2013-03-22 14:43:14

标签: python python-2.6

# Get the user's first name.
first_name = input('Enter your first name: ')

# Get the user's last name.
last_name = input('Enter your last name: ')

# Print a greeting to the user.
print('Hello', first_name, last_name)

2 个答案:

答案 0 :(得分:3)

使用raw_inputprint 声明

# Get the user's first name.
first_name = raw_input('Enter your first name: ')

# Get the user's last name.
last_name = raw_input('Enter your last name: ')

# Print a greeting to the user.
print 'Hello', first_name, last_name

Python 3将旧的raw_input函数重命名为input;在Python 2中,input()意味着与eval(raw_input())相同,它将尝试解释作为Python表达式给出的输入。

您可能希望安装Python 3或考虑切换教程。

答案 1 :(得分:1)

使用raw_input代替... input尝试评估它在python 2.x中获得的内容