Which Python module is used for working with CSV files?
(A) os
(B) csv
(C) json
(D) pickle
Which method is used to write a row of data into a CSV file in Python?
(A) write()
(B) writerow()
(C) writer()
(D) reader()
Which mode is used to open a CSV file for writing?
(A) r
(B) rb
(C) w
(D) a
What does the writerows() method do in Python’s CSV module?
(A) Writes a single row of data
(B) Writes multiple rows of data
(C) Reads multiple rows of data
(D) Appends rows to a file
How can you read from a CSV file in Python?
(A) csv.writer()
(B) csv.reader()
(C) csv.writerow()
(D) csv.read()
Which file mode should be used to append data to an existing CSV file?
(A) r
(B) w
(C) a
(D) x
What does the close() method do after writing into or reading from a CSV file?
(A) Saves changes and closes the file
(B) Reopens the file for reading
(C) Appends new data
(D) Deletes the file
Which of the following is true about CSV files?
(A) CSV files store data in binary format
(B) CSV files store data in a structured, tabular format
(C) CSV files are limited to numerical data
(D) CSV files can only be read in Excel
Assertion-Reasoning :
Assertion (A): The writerow() method can be used to write a single row of data into a CSV file. Reason (R): The writerow() method can only write strings into a CSV file.
(A) Both A and R are true, and R is the correct explanation of A.
(B) Both A and R are true, but R is not the correct explanation of A.
(C) A is true, but R is false.
(D) A is false, but R is true.
Assertion (A): The reader() method in Python is used to read data from a CSV file. Reason (R): The reader() method returns each row of the file as a string.
(A) Both A and R are true, and R is the correct explanation of A.
(B) Both A and R are true, but R is not the correct explanation of A.
(C) A is true, but R is false.
(D) A is false, but R is true.
Programming Questions:
Write a Python program to open a CSV file and write a list of names into it using the writerow() method.
Write a Python program to open a CSV file and append new data using the writerows() method.
Write a Python program to read all the rows from a CSV file using the csv.reader() method.
Write a Python program to read and display the content of a CSV file row by row.
Write a Python program to create a CSV file and store student information (name, age, grade) using the writer() and writerow() methods.
Write a Python program to read data from a CSV file and count the number of rows.
Write a Python program to search for a specific value in a CSV file and display the corresponding row.
Write a Python program to update data in a CSV file by reading the content, modifying a row, and writing it back.
Write a Python program to handle exceptions while reading and writing to a CSV file using the csv module.
Write a Python program to create a CSV file, write multiple rows of data, and close the file properly to ensure data integrity.