【发布时间】:2015-02-09 06:54:18
【问题描述】:
我不明白为什么下面的 Python 代码会打印出一个包含大写字母的句子...请解释一下! :)
def lower(text):
text = text.lower()
example = "This sentence has BIG LETTERS."
lower(example)
print(example)
输出将是:
This sentence has BIG LETTERS.
【问题讨论】:
-
为什么需要自定义函数而不是 example.lower()?
-
因为你不返回任何东西,虽然你可以使用
text.lower()但是如果你确实想使用该功能,你需要return text -
这是一个最小(非)工作示例。我有意在文本中加入更多操作。