2013-02-24 35 views
0

想我的第一PROGRAMM与Python 3.3.0的Python 3.3.0错误

print ("cookies") 
x= input ("enter your name") 
print ("good day to you sir ") + x 

当我要开始我的PROGRAMM与F5它说

Traceback (most recent call last): 
    File "C:/Users/xxxx/Desktop/cookies.py", line 3, in <module> 
    print ("good day to you sir ") + input 
TypeError: unsupported operand type(s) for +: 'NoneType' and 'builtin_function_or_method' 

回答

1

打印值正确的方法是print ("hello", input)print ("hello" + input)

4
print ("good day to you sir ") + x 

print是在Python 3的函数,因此在括号属于福nction。 print函数本身的返回值为None,所以您实际上做的是None + x,这会引发您得到的错误。

你想要做的,而不是什么是直接Concat的两个字符串,括号内:

print("good day to you sir " + x) 

而且您的异常实际上是一个有点不同,但你仍然有print(..) + input(我想这是一个老)请注意,input是从用户获取数据的函数的参考,因此您实际上尝试添加None和函数引用。

0

要打印的所有文本和变量必须位于打印功能的括号内。

所以不是:

print("good day to you sir ") + x 

这将是:

print("good day to you sir " + x) 

或者,你也可以使用,而不是加号的逗号自动给出一个空间:

print("good day to you sir", x) 

代码的其他部分都很好。