创建一个名为mypython.txt文件,文件中包含三行字符串,分别为:
where there is a will,> there is a way.> 有志者事竟成。以只读方式读取打开该文件,并分别用三种方式读取全部内容,输出到屏幕上。
2023-09-01
参考答案:
file_object = open('mypython.txt','r')print(file_object.read())file_object.close() file_object = open('mypython.txt','r')print(file_object.readline())print(file_object.readline())print(file_object.readline())file_object.close() file_object = open('mypython.txt','r')print(file_object.readlines())file_object.close()
热门标签