CSV in Python class 12 offers assignments and questions answers on data file handling in python CBSE class 12 computer science.
CSV in Python class 12 Questions and Answers
Here in we go for CSV in Python class 12 questions and answers.
Objective type questions
Fill in the blanks A _________ is a file format which stores records separated by comma.
.CSV One row of CSV file can be considered as _______ in terms of database.
Text Editor, Spreadsheet or Notepad, MS Excel The writerow() function is a part of _________ module.
CSV A _____ function allows to write a single record into each row in CSV file.
writerow() The _________ parameter of csv.reader() function is used to set a specific delimiter like a single quote or double quote or space or any other character.
dialect A ________ is a parameter of csv.reader() function that accpets the keyword arguments.
**fmtparams When you read csv file using csv.reader() function it returns the values in _______ object.
nested list A ________ parameter is used to quote all fields of csv files.
quotechar The ____________ parameter instructs writer objects to only quote those fields which contain special characters such as delimiter, quotechar or any of the characters in lineterminator.
 To avoid quote fields in csv.writer() function, use _________ parameter.
 If you want to change a default delimiter of csv file, you can specify ________ parameter.
delimiter CSV module allows to write multiple rows using ____________ function.
writerrows() ___________ instances or objects return by the writer function.
True/False – CSV in Python class 12 Each row read from the csv file is returned as a list of strings.
True You can import csv module functions in following manner:
from csv import writerow, reader
True The csv.QUOTE_NONNUMERIC is used to quotes all kind of data.
False When csv.QUOTE_NONE is used with writer objects you have to specify the escapechar option parameter to writerow() function.
True You cannot change the by default comma as a value separater.
False The quotechar function must be given any type of character to separate values.
True The default line terminator is \n in csv file.
True The write row function creates header row in csv file by default.
False You cannot insert multiple rows in csv file using python csv module.
False In csv file, user can insert text values and date values with single quote like MySQL.
MCQs/One word Answer Questions – CSV in Python class 12
- Expand: CSV
- Comma Separated Value
- Which of the following module is required to import to work with CSV file?
- Which of the following is not a function of csv module?
- The writer() function has how many mandatory parameters?
- Name the function which used to write a row at a time into CSV file.
- Which of the following parameter needs to be added with open function to avoid blank row followed file each row in CSV file?
- Anshuman wants to separate the values by a $ sign. Suggest to him a pair of function and parameter to use it.
- writer, delimiter
- Which of the following is tasks cannot be done or difficult with CSV module?
- Data in tabular form
- Uniqueness of data
- Saving data permanently
- All of these
- Which of the following is by default quoting parameter value?
- Which of the following is must be needed when csv.QUOTE_NONE parameter is used?
- None of these
Descriptive Questions CSV in python class 12
 Write the functions required to handle CSV files.
To handle CSV files following function required:
 Write to ways to import a csv module.
- import csv
- from csv import *
Case study based questions – CSV in Python class 12 Write python code to create a header row for CSV file “students.csv”. The column names are : Adm.No, StudentName, City, Remarks
Creating a header row is one of the most important aspects of CSV in python class 12. Use the following code to do so.
 Observe the following code and fill in the given blanks:
from csv import writer f = open("students.csv","w") dt = writer(f) dt.writerow(['Admno','StudentName','City','Remarks']) f.close()
import csv with _________ as f: #1 r = csv.______(f) #2 for row in ______: #3 print(_____) #4
- Import csv module – import csv
- Open the csv file in reading mode – f = open(“demo.csv”,”r”)
- Use list object to store the data read from csv using reader – data = csv.reader(f)
- close the csv file – f.close()
- print the data object – print(data)
 Write code to insert multiple rows in the above csv file.
from csv import reader f = open("cust.csv","r") dt = reader(f) data = list(dt) f.close() for i in data: for j in i: print('\t|',j,end=" ") print()
 Write code to delete a row from csv file.
from csv import writer with open("cust.csv","a",newline="\n") as f: dt = writer(f) while True: sno= int(input("Enter Serial No:")) cust_name = input("Enter customer name:") city = input("Enter city:") amt = int(input("Enter amount:")) dt.writerow([sno, cust_name, city, amt]) print("Record has been added.") print("Want to add more record?Type YES!!!") ch = input() ch = ch.upper() if ch=="YES": print("*************************") else: break
import csv record = list() custname= input("Please enter a customer name to delete:") with open('cust.csv', 'r') as f: data = csv.reader(f) for row in data: record.append(row) for field in row: if field == custname: record.remove(row) with open('cust.csv', 'w') as f: writer = csv.writer(f) writer.writerows(record)
Share this article with your friends and classmates.
Ask your doubt in comment section.
Thank you for reading this article CSV in Python class 12 questions and answers.