Python に問題があり、助けが必要です。関数を呼び出すと、出力が表示されなくなりました<function hello at 0x0000000002CD2198>
(hello は関数名です)。Python を再インストールしましたが、問題は残ります。先日は晴れていて、一見理由もなく発生し始めました。
これを解決するにはどうすればよいですか?
関数を呼び出す必要があります。関数オブジェクト自体だけを出力しています。
>>> def hello():
... return "Hello World"
...
>>> print hello()
Hello World
>>> print hello
<function hello at 0x1062ce7d0>
hello
と行の違いに注意してくださいhello()
。
call function as func()
、関数は前に括弧を付けて呼び出されます:
>>> def hello():
print "goodbye"
>>> hello() #use parenthesis after function name
goodbye
>>> hello #you're doing this
<function hello at 0x946572c>
>>>hello.__str__()
'<function hello at 0x946572c>'
私はあなたが電話hello
したと思います
hello
hello()
代わりに試す
完全を期すために:
が実際に呼び出されていたとしても、単に別の関数を返すだけhello
である可能性はもちろんあります。hello()
このことを考慮:
def hello():
"""Returns a function to greet someone.
"""
def greet(name):
return "Hello %s" % name
# Notice we're not calling `greet`, so we're returning the actual
# function object, not its return value
return greet
greeting_func = hello()
print greeting_func
# <function greet at 0xb739c224>
msg = greeting_func("World")
print msg
# Hello World