Python--输入输出和文件读写

#输入输出

# input( )接受用户输入
str_1 = input("请输入:")
str_2 = input("请再输入:")

print('str_1 is '+ str_1+'  str_2 is '+str_2)
print("str_1 is {}   str_2 is {}".format(str_1,str_2))
#写出文件
some_sentences ='''
1234
5678
9876
5432
'''

f = open('sentences.txt','w')
f.write(some_sentences)
f.close()
#读入文件
f = open('sentences.txt','r')  #写不写'r'结果一样
while True:
    line = f.readline()
    if len(line) == 0:
        break
    print(line)
f.close()

猜你喜欢

转载自blog.csdn.net/qq_38173003/article/details/81060209
今日推荐