s = 'good'
with open('5.txt', 'r') as f:
data = f.readlines()
for i,j in enumerate(data):
j = j.replace('\n', '')
if j==s:
print('第{0}行的数据为{1}'.format(i, j))
栗子肉的博客点击查看python把一个字符串列表写入txt文件,并保证每个字符串占用一行且没有其他符号(例如[]‘’空格)具体信息答:代码如下: #coding=utf-8a = ['zali','sili','ann']with open('test.txt', 'w') as f: for i in ...