Python是强大的数据处理工具,能方便读写文件。 打开D:\test.csv,文件的内容如下图所示, >>>f=open(r"D:\test.csv",'r') >>>s1=f.read() >>>s2=f.read() >>>f.close() 运行上述程序,说法正确的是?( )

A: >>>s1 'hello python!'
B: >>>s1 'hello word!'
C: >>>s1 'hello python!\nhello word!\n'
D: >>>s2 'hello python!\nhello word!\n'
正确答案:C
答案解析
试题解析:
read()函数的使用
>>>f=open(r"D:\test.csv",'r')
>>>s1=f.read() #从文件指针所在位置,读到文件结尾
>>>s2=f.read()#读取到了0个字节,因为文件指针已经读到文件尾部
>>>f.close()
>>>s1
'hello word!\nhello word!\n'
>>>s2
试卷来源:202312 青少年软件编程等级考试Python三级真题