← All Python MCQ topics and your readiness dashboard
Test your Files, JSON and CSV knowledge with a timed Python MCQ mock test for interviews. Each attempt gives you 20 random questions in 20 minutes from a 200-question bank covering open modes, reading and writing text and binary files, encodings and line endings, pathlib, os and shutil, json dump and load with its type rules, JSON Lines, the csv module with DictReader and DictWriter, quoting and delimiters, BOMs, StringIO and tempfile, TOML and INI config, and data-driven tests, tmp_path, downloads, uploads, exports and snapshots for QA. 59 questions are written from a QA and test-automation angle and the rest from a developer angle; your result shows both scores.
What this Python MCQ test covers
Revise these lessons from the free Python tutorial before or after your test:
Sample Python Files, JSON & CSV questions with answers
- Q. Loading test data from a JSON file. What does this code print?
import json
with open("users.json", "w") as f:
json.dump([{"user": "asha", "ok": True}, {"user": "", "ok": False}], f)
with open("users.json") as f:
cases = json.load(f)
print(len(cases), [c["user"] or "<empty>" for c in cases])
Answer:2 ['asha', '<empty>']
Load the cases once and feed them to parametrize. - Q. Building parametrize cases from a CSV file. What does this code print?
import csv
with open("login.csv", "w", newline="") as f:
f.write("user,password,expected\nasha,ok1,200\nbad,x,401\n")
with open("login.csv", newline="") as f:
cases = [(r["user"], r["password"], int(r["expected"])) for r in csv.DictReader(f)]
print(cases)
Answer:[('asha', 'ok1', 200), ('bad', 'x', 401)]
Convert CSV strings to the right types when building cases. - Q. Comparing a JSON response with a saved snapshot. What does this code print?
import json
expected = {"id": 7, "roles": ["qa", "admin"]}
with open("snap.json", "w") as f:
json.dump(expected, f, sort_keys=True, indent=2)
actual = {"roles": ["qa", "admin"], "id": 7}
with open("snap.json") as f:
print(json.load(f) == actual)
Answer:True
Comparing loaded dicts ignores key order, so the snapshot matches. - Q. What does this code print?
with open("a.txt", "w") as f:
f.write("hello")
with open("a.txt") as f:
print(f.read())
Answer:hello
Write the text, then read it back. - Q. What does this code print?
with open("a.txt", "w") as f:
n = f.write("hello\n")
print(n)
Answer:6
write() returns the number of characters written, including the newline. - Q. What does this code print?
with open("a.txt", "w") as f:
f.write("one")
with open("a.txt", "w") as f:
f.write("two")
print(open("a.txt").read())
Answer:two
Mode "w" truncates the file first.
Every predict-the-output question in this bank was run on Python 3, so the answer is the real output. Go back to the Python MCQ dashboard to see your overall Python learning progress and interview readiness.
Frequently asked questions
How many questions does the Python Files, JSON & CSV MCQ test have?
The bank has 200 questions. Each test picks 20 at random, favouring questions you have not seen yet, so about 10 attempts cover the whole bank.
How long is each test and what is the pass mark?
Each test has a 20-minute timer and submits itself when time runs out. You pass with 70%, which is 14 of 20 correct.
Is this test useful for QA and automation engineer interviews?
Yes. 59 of the questions use test-automation scenarios such as parsing UI text, test data and assertions, and your result shows your QA score separately.
Can I retake the test?
Yes, as often as you like. Every retake draws a fresh set of 20 questions and counts toward your 20-test readiness target.