w3ajay

tally tutorial point, ms word 2013, ms excel 2013, ms powerpoint 2010,ccc question with answer in hindi 2021, Tally Prime in hindi , tally prime,Python,in python,programming in python,python

Sunday, August 18, 2024

Program for write in csv file class 12



How do I write a CSV file?

 To write data into a CSV file in Python, we use the csv.writer() function to create a writer object that can write data to the file. The writer object has methods like writerow() and writerows() that can write one or more rows of data to the file.

Program for write single row in csv file 



#Program for write in csv file

import csv

fobj=open("ram.csv","w",newline='')

f=csv.writer(fobj)

data=['roll','name','marks']

f.writerow(data)

fobj.close()

Program for write single row and multiple rows in csv file 



Program


#Program for write in csv file
import csv
fobj=open("ram.csv","w",newline='')
f=csv.writer(fobj)
data=['roll','name','marks']
f.writerow(data)
data2=[[1,'Devansh',99],[2,'Divyansh',88],[3,'Ajay',77],
       [4,'pavan',87],[5,'abhay',76]]
f.writerows(data2)

fobj.close()


Output


Like Share



2 comments:

for more information please share like comment and subscribe