NCERT Class 12 Computer Science Computer Science: Chapter 2 — File Handling in Python

NCERT CBSE Class 12 Computer Science Computer Science Chapter 2 English PDF

This chapter introduces File Handling in Python, a crucial concept for permanent data storage beyond program execution. It explains that variables have a limited lifetime, necessitating the use of files on secondary storage devices for reusability. The chapter defines a file as a named location for permanent data storage. It then delves into the two main types of data files: text files and binary files. Text files contain human-readable characters (like.txt,.py,.csv) and are stored using encoding schemes like ASCII or UNICODE, where each character is represented by bytes. Binary files, on the other hand, are non-human-readable collections of 0s and 1s requiring specific programs to access. The chapter highlights that text files use special End of Line (EOL) characters, such as newline (\n) in Python, to denote the end of a line, facilitating structured data storage. This chapter is essential for students to understand how to manage and persist data effectively in their Python programs, a key skill for CBSE Computer Science.

Quick info

BoardCBSE / NCERT
ClassClass 12
SubjectComputer Science
BookComputer Science
ChapterChapter 2 — File Handling in Python
LanguageEnglish
PDF typeNCERT Textbook
SessionCBSE 2026
Reading time3 minutes
Word count429

Learning outcomes

Vocabulary

WordMeaning
DebuggingRunning a partly-understood program to see if it does what you expected.
FileA named location on a secondary storage media where data are permanently stored for later access.
Text fileA file consisting of human-readable characters, which can be opened by any text editor.
Binary fileA file made up of non-human-readable characters and symbols, requiring specific programs to access.
ASCIIA character encoding standard where each character is represented by a unique number (byte).
UNICODEA character encoding standard that supports a wide range of characters from different languages.
EOLEnd of Line character, a special character that terminates each line in a text file (e.g., \n in Python).
NewlineThe special character (\n) used in Python to indicate the end of a line in a text file.

The complete chapter text is read in the official NCERT PDF viewer below (streamed from ncert.nic.in). This page provides NCERT Help study material — summary, vocabulary, practice questions, and FAQs — not a full reproduction of the textbook.

Read chapter online

This PDF is loaded from the official NCERT website (ncert.nic.in). Use the page buttons below to read — download is disabled on NCERT Help.

Read page by page below. PDF is streamed from the official NCERT website — no download button on this page.

Loading document …
Page of
Loading page …

Practice questions

  1. Why is it necessary to store data permanently? Answer: Data needs to be stored permanently to reuse it later, avoiding repetitive tasks of entering the same data, and for organizational needs like storing employee or sales information.
  2. What is the difference between a text file and a binary file? Answer: Text files contain human-readable characters and can be opened by text editors, while binary files contain non-human-readable bytes and require specific programs to access their contents.
  3. What is a file in the context of computer storage? Answer: A file is a named location on a secondary storage device where data is permanently stored for later access.
  4. What is the purpose of an EOL character in a text file? Answer: An EOL character signifies the end of a line in a text file, allowing text editors or programs to display the file content on separate lines.

Practice MCQs

Q1. Which of the following is NOT a reason for permanent data storage?

Q2. A file with the.txt extension is typically considered a:

Q3. What does a text editor do when opening a text file?

Q4. The default End of Line (EOL) character in Python is:

Q5. Which of the following is an example of a text file extension?

Frequently asked questions

What is the primary purpose of file handling in Python?

File handling in Python allows programs to store data permanently on secondary storage devices, making it reusable beyond the program's execution.

Can I open a text file with a text editor?

Yes, text files are designed to be human-readable and can be opened and viewed using any standard text editor like Notepad or VS Code.

How are text files different from binary files?

Text files store data as human-readable characters using encoding schemes, while binary files store data as raw bytes (0s and 1s) which are not directly human-readable.

What does the ASCII value 65 represent in a text file?

In ASCII encoding, the value 65 represents the uppercase letter 'A'.

What is the significance of the '\n' character in Python text files?

The '\n' character is the newline character, which acts as an End of Line (EOL) marker, indicating that the subsequent content should start on a new line.

Why is a.docx file larger than a.txt file containing the same text?

.docx files contain additional formatting information, metadata, and structural data beyond the plain text, making them larger than simple.txt files.

Related resources

Important topics

Introduction to Files Types of Files (Text vs. Binary) Text File Storage Mechanism Binary File Storage Mechanism End of Line (EOL) Characters

Topics covered

Introduction to Files Types of Files Opening and Closing a Text File Writing to a Text File Reading from a Text File Setting Offsets in a File Creating and Traversing a Text File The Pickle Module File Definition Text File Characteristics Binary File Characteristics Character Encoding (ASCII, UNICODE)

NCERT Class 12 Computer Science — Computer Science — Chapter 2 — File Handling in Python. Verified by NCERT Help Editorial Team. Reviewed on 29 Jul 2026. Last updated 10 Aug 2026.