TypeError:无法连接'str'和'builtin_function_or_method'对象
问题描述:
此代码有什么问题?TypeError:无法连接'str'和'builtin_function_or_method'对象
def welcome(name):
print "congrats! You created your first Python bank account"+ name
print "Hello welcome to the Python bank Account"
print"To begin please enter your name"
name=raw_input
welcome(name)
答
raw_input()
是一个函数,所以你必须调用它,使其工作,也接受被打印在调用时可选参数:
name=raw_input("To begin please enter your name")
例如:
In [61]: name=raw_input("enter your name")
enter your name foo bar
In [62]: name
Out[62]: ' foo bar'
只做name=raw_input
只是创建一个新的参考raw_input
,所以 你实际上试图连接一个字符串和raw_input
在你的函数 welcome
其引发的错误:
In [63]: name=raw_input
In [64]: name
Out[64]: <function raw_input>
答
使用raw_input()
而不是raw_input
。
raw_input
是一个函数,你必须调用函数来返回一个字符串,否则返回一个函数对象。
答
尝试:
name = raw_input()
原料输入的功能,当你想打电话给你应该使用() 例如:
>>> s = raw_input('--> ')
--> Monty Python's Flying Circus
>>> s
"Monty Python's Flying Circus"
'名称=的raw_input( )' – 2013-04-26 16:28:38
这是为了我们的测验吗?否则,您会向我们提供您的预期和您实际得到的内容...... – glglgl 2013-04-26 16:30:05
它不会创建_real_银行帐户 – 2013-04-26 16:30:15