1. How do you open a file named data.txt in read mode in Python?
2. What is the purpose of the with statement in file handling?
3. How can you write data to a file in Python?
4. What does the read() method of a file object do?
5. How can you read a single line from a file in Python?
6. What is the purpose of the seek() method in file handling?
7. How can you read the entire contents of a file line by line in Python?
8. What is the output of the following code:
with open('data.txt', 'a') as file:
file.write('Appended line.')
with open('data.txt', 'r') as file:
content = file.read()
print(content)
with open('data.txt', 'a') as file:
file.write('Appended line.')
with open('data.txt', 'r') as file:
content = file.read()
print(content)