Read and Write File with Python

Basic read and write file with python 3.x.

Photo by Beatriz Pérez Moya on Unsplash

test.txt

Open and Read Files

‘r’ means read, it is default value, we can use file = open(‘test.txt’) as well . use file.close() to close file.

output:

Write/Create File

‘w’ means create new or overwrite file content. We can use ‘a’ for append in the end of file content.

--

--

Software Engineer, Indonesia

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store