如何使 lower() 方法适用于读取文件
在 python 中,我正在读取一个文件,然后尝试将所有内容转换为小写,但它没有改变。我做错了什么?
fstor = open(txt)
story = fstor.read()
story.lower()
输出(我清理了标点符号和其他标记)
日子一天天过去,最聪明的小猪的房子已经建成了 砖头 他的兄弟们时不时地来看望他,笑着说 你为什么这么努力为什么不来玩但是 顽固的瓦工猪只说不 我将首先完成我的房子 它必须坚固耐用 然后我会
In python, I am having a file read then trying to convert everything to lower case but it isn't changing. What am I doing wrong?
fstor = open(txt)
story = fstor.read()
story.lower()
OUTPUT ( I cleaned up punctuations and other marks )
The days went by and the wisest little pig's house took shape brick by
brick From time to time his brothers visited him saying with a chuckle
Why are you working so hard Why don't you come and play But the
stubborn bricklayer pig just said no
I shall finish my house first It must be solid and sturdy And then I'll
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
字符串在
python
中是不可变输出:
将数据写入另一个文件
Strings are immutable in
python
Output:
Write the data to another file
这段代码有效:)
works this code :)