Python – Writing into File:

In this tutorial, we will learn how to write into a file in Python. Writing the data into a file can be done by using the “write()” method. The write() method takes string as an argument. Let us see an example of writing the data into the file called “techsal.csv”.

First creating the data in a file called “techsal.csv”. Below is the data how it looks.

designers, 100, salary, 10000

programmers, 1000, salary, 15000

Dataadmins, 10, salary, 12000

Let us write a line into the same file.

Let us read the data from the file.

Below is the output:

Finally closing the file: