【发布时间】:2015-07-11 07:11:39
【问题描述】:
如何从已加载到 Python 中的文本文件的所有行中替换特定行的最后一个单词?我知道如果我想以列表的形式访问它,我会使用 [-1] 来表示特定的行,但我不知道如何将它作为字符串来访问。文本文件的一个例子是:
A I'm at the shop with Bill.
B I'm at the shop with Sarah.
C I'm at the shop with nobody.
D I'm at the shop with Cameron.
【问题讨论】:
-
line.split()[-1]给你一串单词的最后一个单词
标签: python