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

Python File Operations Explained

Uploaded by

BADASS GAMING YT
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)
4 views2 pages

Python File Operations Explained

Uploaded by

BADASS GAMING YT
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

Experiment: 03

Aim : Operations on file in python.

Theory:

In Python, there are several operations that can be performed on files. Some of the
common file operations in Python are:

Opening a file
Reading a file
Writing to a file
Appending to a file
Closing a file
Renaming a file
Deleting a file

Program:

Aim : Opening a file in write mode


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

Aim : Writing to a file


[Link]("Hello, World!")
[Link]("\nThis is an example file.")

Aim : Closing a file


[Link]()

Aim : Opening a file in read mode


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

Aim : Reading a file


print([Link]())

Aim : Closing a file


[Link]()

Aim : Opening a file in append mode


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

Aim : Appending to a file


[Link]("\nThis is an appended line.")

Aim : Closing a file


[Link]()
Aim : Renaming a file
import os
[Link]("[Link]", "new_example.txt")

Aim : Deleting a file


[Link]("new_example.txt")

Output:

Conclusion: We have Performed Operations on file in Python

You might also like