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]()