read,readline,readlines的特点与区别
1.read
- 读取全部文件
with open("test.text", "r",encoding='utf8') as f:
print(f.read())
输出:
2.readline
- 读取下一行
with open("test.text", "r",encoding='utf8') as f:
# print(f.read())
for i in range(10):
print(f.readline())
输出:
3.readlines
- 读取全部,并返回一个列表
with open("test.text", "r",encoding='utf8') as f:
print(f.readlines(), type(f.readlines()))
输出: