# the string you want so search fromsome_string = 'first line /n second line'# split the string into a list divided by '/n' (enter) some_string = some_string.split('/n')# print the lines that have a specific wordword = 'second'for line in some_string: if word in line: print(line)一个例子是这样的。您可以随意修改它,以便它更适合您的问题