python - 简单 Python 代码中的 Str 对象错误

标签 python string bash unix terminal

我正在尝试回显用户的输入,然后再次以大写和小写形式回显。我收到这个而不是我预期的输出:

<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/

相关文章:

python - 我正在寻找一个可以播放 MP3 和 OGG 并支持 ALSA 或类似的跨平台 Python 库

python - 统一码编码错误 : 'ascii' codec can't encode characters in position 0-3: ordinal not in range(128)

c - 有条件地列出字符串数组

c - 回文函数总是报告错误的偏移量 #1

JavaScript计算字符串的长度

bash - 执行带有 Bash 变量的命令并存储结果

linux - Bash 脚本 + 移动多个变量

linux - scp 无法从 vagrant box 中的 bash 脚本运行

python - 像 QTextEdit 这样的 QWidget 会自动将其高度包装到其内容中?

python - all()函数的正确使用