NCERT Class 12 Computer Science Computer Science: Chapter 2 — File Handling in Python
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
| Board | CBSE / NCERT |
|---|---|
| Class | Class 12 |
| Subject | Computer Science |
| Book | Computer Science |
| Chapter | Chapter 2 — File Handling in Python |
| Language | English |
| PDF type | NCERT Textbook |
| Session | CBSE 2026 |
| Reading time | 3 minutes |
| Word count | 429 |
Learning outcomes
- Understand the need for permanent data storage using files.
- Differentiate between text files and binary files.
- Explain how data is stored in text files using character encoding.
- Recognize the role of End of Line (EOL) characters in text files.
Vocabulary
| Word | Meaning |
|---|---|
| Debugging | Running a partly-understood program to see if it does what you expected. |
| File | A named location on a secondary storage media where data are permanently stored for later access. |
| Text file | A file consisting of human-readable characters, which can be opened by any text editor. |
| Binary file | A file made up of non-human-readable characters and symbols, requiring specific programs to access. |
| ASCII | A character encoding standard where each character is represented by a unique number (byte). |
| UNICODE | A character encoding standard that supports a wide range of characters from different languages. |
| EOL | End of Line character, a special character that terminates each line in a text file (e.g., \n in Python). |
| Newline | The 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.
Practice questions
- 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.
- 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.
- 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.
- 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?
Explanation: Permanent data storage is for data that needs to be accessed even after program execution has finished, not just during it.
Q2. A file with the.txt extension is typically considered a:
Explanation: Files with extensions like.txt,.py, and.csv are examples of text files, containing human-readable characters.
Q3. What does a text editor do when opening a text file?
Explanation: Text editors translate the underlying byte representations (like ASCII values) into characters that humans can read.
Q4. The default End of Line (EOL) character in Python is:
Explanation: The newline character, represented as , is the default EOL character used in Python to mark the end of a line in text files.
Q5. Which of the following is an example of a text file extension?
Explanation: .py files, used for Python scripts, are text files..docx is a document file,.exe is an executable, and.zip is a compressed file.
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
Topics covered
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.