# 文件输入输出
# 1. 写入文件
# 右斜杠是顶格操作
str_1 ='''\
I love learning python
because python is fun
and also easy to use'''
# 第一个参数,文件名,对二个参数,操作方式
f = open("sentence.txt",'w')
f.write(str_1)
f.close()
# 读入一个文件
fp = open("sentence.txt","r") # 默认读文件
while True :
line = fp.readline()
if len(line) == 0:
break
print(line)
fp.close()
python学习8 ---文件输入输出
最新推荐文章于 2023-02-21 01:01:23 发布