0% found this document useful (0 votes)
2 views2 pages

Python File Handling for Class 12

The document provides an overview of file handling in Python for Class 12, detailing how to create, write, read, append, and close files. It explains various file modes such as read, write, append, and create, along with code examples for each operation. Additionally, it offers tips for teachers on effectively teaching the topic through theory, demonstrations, and hands-on practice.

Uploaded by

sahaparikshit5
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Python File Handling for Class 12

The document provides an overview of file handling in Python for Class 12, detailing how to create, write, read, append, and close files. It explains various file modes such as read, write, append, and create, along with code examples for each operation. Additionally, it offers tips for teachers on effectively teaching the topic through theory, demonstrations, and hands-on practice.

Uploaded by

sahaparikshit5
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

File Handling in Python - Class 12

File Handling in Python


Class 12 - Text File Handling

Presented in Simple Steps

What is File Handling?


It allows us to:

- Create files

- Write data

- Read data

- Append data

- Close files after use

File Modes in Python


"r" - Read

"w" - Write

"a" - Append

"x" - Create

Writing to a File
file = open("[Link]", "w")

[Link]("Hello")

[Link]()

Reading from a File


file = open("[Link]", "r")

content = [Link]()

print(content)
[Link]()

Appending to a File
file = open("[Link]", "a")

[Link]("\nNew Line")

[Link]()

Read Line by Line


file = open("[Link]", "r")

for line in file:

print(line)

[Link]()

Using with Statement


with open("[Link]", "r") as file:

data = [Link]()

print(data)

Tips for Teachers


- Start with theory

- Show live demo in IDLE

- Explain file modes

- Encourage hands-on practice

You might also like