data.txt文本内容
dog
person
cat
with open('data.txt') as f:
data = f.readlines()
print(data)
with open('data.txt') as f:
data = f.read().splitlines()
print(data)
with open('data.txt') as f:
for line in f.readlines():
line=line.strip('\n')
print(line)
输出:
['dog\n', 'person\n', 'cat']
['dog', 'person', 'cat']
dog
person
cat