File Handling in Python
CBSE · Class 12 · Computer Science
NCERT Solutions for File Handling in Python — CBSE Class 12 Computer Science.
Interactive on Super Tutor
Studying File Handling in Python? Get the full interactive chapter.
Quizzes, flashcards, AI doubt-solver and a step-by-step study plan — built for ncert solutions and more.
1,000+ Class 12 students started this chapter today

Super Tutor has 9+ illustrations like this for File Handling in Python alone — flashcards, concept maps, and step-by-step visuals.
See them all11 worked solutions below. Unlock all 21 free in Super Tutor
EXERCISE
1Differentiate between:Show solution
- Binary file: contains non-human-readable data in bytes; needs specific programs to access it.
Not sure why a step works? check your working in Super Tutor
1(a)text file and binary fileShow solution
- A text file consists of readable characters such as alphabets, numbers, and symbols. Its contents are stored as ASCII/Unicode byte values and can be opened in a text editor.
- A binary file stores data as bytes that do not represent readable characters. It may contain images, audio, video, executable files, etc., and needs specific software to read or write it.
Not sure why a step works? check your working in Super Tutor
1(b)readline() and readlines()Show solution
- readlines() reads all lines from a file and returns them as a list of strings.
Not sure why a step works? check your working in Super Tutor
1(c)write() and writelines()Show solution
- writelines() writes multiple strings from an iterable like a list or tuple, and it does not return the number of characters written.
Not sure why a step works? check your working in Super Tutor
2(a)open()Show solution
Syntax:
```python
file_object = open(file_name, access_mode)
```
Not sure why a step works? check your working in Super Tutor
2(b)read()Show solution
Syntax:
```python
file_object.read(n)
```
If no argument or a negative value is given, it reads the entire file.
Not sure why a step works? check your working in Super Tutor
2(c)seek()Show solution
Syntax:
```python
file_object.seek(offset[, reference_point])
```
- `offset` = number of bytes to move
- `reference_point` = starting position: `0` beginning, `1` current position, `2` end of file
Not sure why a step works? check your working in Super Tutor
2(d)dump()Show solution
Syntax:
```python
dump(data_object, file_object)
```
Not sure why a step works? check your working in Super Tutor
3(a)a text file “example.txt” in both read and write modeShow solution
Statement:
```python
file_object = open("example.txt", "r+")
```
Not sure why a step works? check your working in Super Tutor
3(b)a binary file “bfile.dat” in write modeShow solution
Statement:
```python
file_object = open("bfile.dat", "wb")
```
Not sure why a step works? check your working in Super Tutor
3(c)a text file “try.txt” in append and read modeShow solution
Statement:
```python
file_object = open("try.txt", "a+")
```
Not sure why a step works? check your working in Super Tutor
P.read(10)
x = P.read()
10 more solved questions in File Handling in Python
Every remaining exercise is solved step by step in Super Tutor, plus practice quizzes and flashcards for this chapter. Free to start.
Stuck on a step?
Ask Super Tutor AI to explain any solution on this page in a simpler way — free, 24x7.
Ask a Doubt FreeFrequently Asked Questions
What are the important topics in File Handling in Python for CBSE Class 12 Computer Science?
How to score full marks in File Handling in Python — CBSE Class 12 Computer Science?
Where can I get free NCERT Solutions for File Handling in Python Class 12 Computer Science?
Sources & Official References
- NCERT Official — ncert.nic.in
- CBSE Academic — cbseacademic.nic.in
- CBSE Official — cbse.gov.in
- National Education Policy 2020 — education.gov.in
Content is aligned to the official syllabus. Refer to the board website for the latest curriculum.
More resources for File Handling in Python
Practice Quiz
Test yourself with a quick quiz
Important Questions
Practice with board exam-style questions
Revision Notes
Key points for last-minute revision
Formula Sheet
All formulas in one place
Chapter Summary
Understand the chapter at a glance
Concept Maps
See how topics connect visually
Study Plan
Step-by-step plan to ace this chapter
Flashcards
Quick-fire cards for active recall
Syllabus
What topics to cover
For serious students
Get the full File Handling in Python chapter — for free.
Quizzes, flashcards, AI doubt-solver and a step-by-step study plan for CBSE Class 12 Computer Science.