Empowering Students with AI-Powered Assessments & Intelligent Learning
Chapter Exam

Chapter-2 File Handling in Python — Online MCQ Test

COMPUTER SCIENCE · Grade 12 · CBSE(NCERT)

Practice Chapter-2 File Handling in Python with a free chapter-wise online MCQ test for CBSE(NCERT) Grade 12 COMPUTER SCIENCE. This chapter covers: text files (.txt) - binary files (.dat) - pickle module - CSV files (.csv) - file reading - file writing. AI-generated questions from basic to board-exam level, with instant results and explanations.

10
Questions
20m
Time Limit
3
Attempts Left
  • 10 random questions from this chapter (mixed difficulty)
  • Questions you've seen before won't repeat until the pool resets
  • You have 20 minutes — exam auto-submits when time is up
  • Maximum 3 attempts per chapter
  • Results and explanations shown immediately after submission
Login to Start This Exam →

New here? Register free — includes 3 free chapter exams.

Chapter-2 File Handling in Python — Important Questions & Answers (FAQ)

Frequently asked questions from CBSE(NCERT) Grade 12 COMPUTER SCIENCE — Chapter-2 File Handling in Python, with answers and explanations. These are sample questions; the exam has its own separate question set.

Which of the following is the correct extension for a text file in Python?
  • A. .txt ✓
  • B. .dat
  • C. .csv
  • D. .py
Answer: A. .txt
Text files in Python use the .txt extension to store plain text data.
What does the 'r' mode do when opening a file in Python?
  • A. Write mode
  • B. Read mode ✓
  • C. Append mode
  • D. Binary mode
Answer: B. Read mode
The 'r' mode opens a file for reading existing content without modifying it.
When you open a file in 'w' mode, what happens if the file already exists?
  • A. It appends to the existing file
  • B. It overwrites the existing file ✓
  • C. It creates a new version of the file
  • D. It raises an error
Answer: B. It overwrites the existing file
Write mode ('w') truncates and overwrites any existing file with the same name.
Analyze this code: What will be the output?\nwith open('test.txt', 'w') as f:\n f.write('Hello')\nwith open('test.txt', 'r') as f:\n print(f.read())
  • A. Hello ✓
  • B. test.txt
  • C. None
  • D. An error occurs
Answer: A. Hello
The code writes 'Hello' to the file, then reads and prints it. The with statement ensures proper file handling.
TRICKY: What will happen if you try to pickle an open file object?
  • A. It will successfully pickle the file path
  • B. It will raise a TypeError because file objects cannot be pickled ✓
  • C. It will pickle the file contents
  • D. It will create a copy of the file
Answer: B. It will raise a TypeError because file objects cannot be pickled
File objects, along with lambda functions and some built-ins, cannot be pickled as they depend on runtime state.

Choose Your Plan & Start Practising

All plans cover every subject and chapter of your registered grade.

Free
₹0
3 exams · 1 year
Start Free →
Active
₹350
12 exams · 1 year
Get Active →
Pro
₹899
Unlimited exams · 1 year
Get Pro →

Compare all plans in detail →