Junior — Middle
Explain the concept of CSV format where data is separated by commas.
sobes.tech AI
Answer from AI
CSV (Comma-Separated Values) is a simple text format for storing tabular data, where each line corresponds to a record, and fields within the line are separated by commas.
Example of CSV:
Name,Age,City
Ivan,30,Moscow
Anna,25,Saint Petersburg
Format features:
- Each line is a separate record.
- Fields are separated by commas.
- If a field contains a comma or quotes, it is enclosed in double quotes.
- The format is easy to read and supported by many programs.
In Python, it is convenient to use the csv module to work with CSV:
import csv
with open('data.csv', newline='', encoding='utf-8') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
print(row['Name'], row['Age'], row['City'])
CSV is widely used for data exchange between systems due to its simplicity and universality.