我正在尝试回显用户的输入,然后再次以大写和小写形式回显。我收到这个而不是我预期的输出:
<built-in method lower of str object at 0x100e205a0>
这是什么意思?
我正在使用这段代码:
#!/usr/bin/env python
phrase = raw_input("Enter a phrase to be capitalized: ")
print phrase
print phrase.lower
print phrase.lower
最佳答案
看起来您只需要将 ()
添加到函数调用的末尾即可。当您键入 print phrase.lower
时,Python 解释器会返回函数对象的描述。如果您改为执行 print phrase.lower()
,它将打印将函数应用于 phrase
的结果。与 Python 中的大多数事物一样,函数是对象。
关于python - 简单 Python 代码中的 Str 对象错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24923806/