top of page

File Operations in Python

Updated: Apr 19, 2023



File operations in Python are simple as seen in the following example.


The open() method is used to open a file.


There are several operations that can be performed on the file. The most important ones are “w” for write, “a” for append, “r” for read.


Text files and binary files can be opened this way.



f = open("a1.txt", 'w')
f.write("Metric Coder")
f.close()

f = open("a1.txt", 'a')
f.write(" Bangalore ")
f.close()

f = open("a1.txt", 'r')
content = f.read()
print(content)
f.close()

The link to the Github repository is here .


3 views

Related Posts

How to Install and Run Ollama on macOS

Ollama is a powerful tool that allows you to run large language models locally on your Mac. This guide will walk you through the steps to...

bottom of page