0
0
Pythonprogramming~5 mins

Reading and writing CSV data in Python - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a CSV file?
A CSV (Comma-Separated Values) file is a simple text file that stores tabular data. Each line is a row, and columns are separated by commas.
Click to reveal answer
beginner
Which Python module is commonly used to read and write CSV files?
The csv module is used in Python to read from and write to CSV files easily.
Click to reveal answer
beginner
How do you open a CSV file for reading in Python?
Use open('filename.csv', 'r', newline='') to open the file in read mode. The newline='' helps handle newlines correctly.
Click to reveal answer
beginner
What does csv.reader do?
csv.reader reads the CSV file line by line and returns each row as a list of strings.
Click to reveal answer
beginner
How do you write rows to a CSV file in Python?
Use csv.writer to create a writer object, then call writer.writerow(row) for each row you want to write.
Click to reveal answer
Which Python code correctly opens a CSV file for writing?
Aopen('data.csv', 'r')
Bopen('data.csv', 'a')
Copen('data.csv', 'w', newline='')
Dopen('data.csv')
What does the csv.reader return for each row?
AA list of strings
BA dictionary
CA string
DAn integer
Which delimiter is used by default in CSV files?
ASemicolon (;)
BComma (,)
CTab (\t)
DSpace ( )
How do you write multiple rows at once using csv.writer?
Awriter.writerows(list_of_rows)
Bwriter.writerow(list_of_rows)
Cwriter.write(list_of_rows)
Dwriter.write_rows(list_of_rows)
Why use newline='' when opening CSV files?
ATo read files faster
BTo add extra blank lines
CTo encrypt the file
DTo prevent extra blank lines on Windows
Explain how to read data from a CSV file in Python step-by-step.
Think about opening the file, reading rows, and what each row looks like.
You got /4 concepts.
    Describe how to write data to a CSV file in Python.
    Focus on opening the file, creating the writer, writing rows, and closing the file.
    You got /4 concepts.