bash 简单 Python 代码中的 Str 对象错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24923806/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Str Object Error in simple Python Code
提问by Yotam
I'm trying echo a user's input, then echo it again in both uppercase and lowercase. I receive this instead of my expected output:
我正在尝试回显用户的输入,然后以大写和小写形式再次回显。我收到这个而不是我预期的输出:
<built-in method lower of str object at 0x100e205a0>
What does that mean?
这意味着什么?
I'm using this code:
我正在使用此代码:
#!/usr/bin/env python
phrase = raw_input("Enter a phrase to be capitalized: ")
print phrase
print phrase.lower
print phrase.lower
回答by Gabriel
Looks like you simply need to add ()
to the end of your function calls. When you type print phrase.lower
the Python interpreter is giving you back a description of the function object. If you instead do print phrase.lower()
it will print the result of applying the function to phrase
. Like most things in Python, functions are objects.
看起来您只需要添加()
到函数调用的末尾。当您键入时print phrase.lower
,Python 解释器会向您返回函数对象的描述。如果您改为这样做print phrase.lower()
,它将打印将该函数应用于phrase
. 与 Python 中的大多数事物一样,函数也是对象。