Ques 1 File Handling
How can you close a file in Python?
a) close()
b) exit()
c) quit()
d) All of the above
Ques 2 File Handling
Which method is used to write data to a file in Python?
a) read()
b) write()
c) append()
d) open()
Ques 3 File Handling
What does the following Python code snippet do?
file = open("filename.txt", "r") file.seek(10) content = file.read() file.close() print(content)
Ques 4 File Handling
How can you iterate over each line in a file using a for loop in Python?
a) for line in file:
b) for line in file.readlines():
c) Both a and b
d) None of the above
Ques 5 File Handling
What will be the output of the following Python code snippet?
file = open("filename.txt", "r") position = file.tell() file.close() print(position)