我在执行python程序时遇到了一个类型错误

时间:2016-09-21 19:15:19

标签: python typeerror

我输入了

x = input("enter name: ")
Print ("hey") + x

但是在编译完成后

Typeerror: unsupported operand type(s) for +: 'nonetype' and 'str'

我正在使用python 3.6.0b1。

2 个答案:

答案 0 :(得分:0)

您正尝试将printNone)的返回值添加到字符串中。正确设置括号非常重要。

x = input("enter name: ")
print("hey" + x)

答案 1 :(得分:0)

print()是一个带字符串的函数调用,所以你需要将括号内的字符串传递给函数调用,如此;

x = input("enter name: ")
print ("hey " + x)

有关print()的更多信息,请访问:https://docs.python.org/3/tutorial/inputoutput.html