如果我们给出上一行中的单词,如何打印下一行

时间:2019-12-26 17:10:51

标签: line next

示例:(name.txt) 萨曼莎是个好女孩 njfha djfhwoa oHWEFHL JAIF ASJFJJIOG AHFUHIEWA CJSHDF SD IOAF JEIWJO JIJFODHUF

代码:

with open('name.txt', 'r') as f:
    for line in f:
        if "samantha" in line:
            print next(line) #it should print all the lines other than samantha line

0 个答案:

没有答案