0% found this document useful (0 votes)
5 views1 page

Python Assignment 4 Complete

The document is an assignment for Python Programming focusing on file handling, detailing the use of the open() function and its modes. It explains various file operations such as reading and writing using functions like read(), readline(), write(), and writelines(). Additionally, it introduces the concept of a file pointer and the seek() function, along with a sample program demonstrating file creation and data manipulation.

Uploaded by

dalipnain621
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)
5 views1 page

Python Assignment 4 Complete

The document is an assignment for Python Programming focusing on file handling, detailing the use of the open() function and its modes. It explains various file operations such as reading and writing using functions like read(), readline(), write(), and writelines(). Additionally, it introduces the concept of a file pointer and the seek() function, along with a sample program demonstrating file creation and data manipulation.

Uploaded by

dalipnain621
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

IMS Engineering College, Ghaziabad

Department of IT/BT

Python Programming – Assignment 4


Course Code: BCC402

Q1. Explain file handling in Python. Describe different modes used in the open() function.
File handling in Python is used to create, read, write and modify files stored on disk.
The open() function is used to open a file.

File Modes:
r : Read mode
w : Write mode
a : Append mode
x : Create mode
rb : Read binary
wb : Write binary
r+ : Read and write
w+ : Write and read

Q2. Explain read(), readline() and readlines() functions.


read() reads the entire file content at once.
readline() reads one line at a time.
readlines() reads all lines and returns a list.

Q3. Explain write() and writelines() functions.


write() writes a single string to the file.
writelines() writes a list of strings to the file.

Q4. What is a file pointer? Explain seek() function.


A file pointer indicates the current position in a file.
The seek() function changes the file pointer position.

Q5. Program to create a file, write data and read it.


file = open('[Link]','w')
[Link]('Python File Handling Assignment')
[Link]()

file = open('[Link]','r')
print([Link]())
[Link]()

You might also like