このコードの何が問題になっていますか?
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)
このコードの何が問題になっていますか?
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
は関数であり、文字列を返すには関数を呼び出す必要があります。それ以外の場合は、関数オブジェクトを返します。