【筆試題】python文件操做

請說出下面代碼結果及緣由,很easy。python

 說明:test.txt文件不存在spa

 

with open('test.txt','w+') as f:
    f.write('34')
    f.seek(0)
    f.write('12')
    f.seek(0)
    print(f.read()) 

輸出結果及緣由:  blog

 

with open('test.txt','a+') as f:
    f.write('34')
    f.seek(0)
    f.write('12')
    f.seek(0)
    print(f.read())  

輸出結果及緣由:it

 

with open('test.txt','a+') as f:
    f.write('3456789')
    f.seek(2)
    f.truncate(3)
    f.write('12')
    f.seek(0)
    print(f.read()) 

輸出結果及緣由: class

相關文章
相關標籤/搜索