Complete the code to open a file named 'data.txt' for reading.
file = open('data.txt', '[1]')
The mode 'r' opens the file for reading.
Complete the code to read the entire content of the file into a variable named 'content'.
content = file.[1]()readline() which reads only one line.write() which is for writing, not reading.The read() method reads the whole file content as a string.
Fix the error in the code to properly close the file after reading.
file = open('data.txt', 'r') content = file.read() file.[1]()
read() again instead of closing.After finishing file operations, always close the file using close().
Fill both blanks to read the entire file content safely using a context manager.
with open('data.txt', '[1]') as file: content = file.[2]()
write() method which is for writing.Using with open(..., 'r') opens the file for reading and automatically closes it. Then read() reads all content.
Fill all three blanks to read the file content and print it.
with open('[1]', '[2]') as file: content = file.[3]() print(content)
write() instead of read().The file name is 'data.txt', mode is 'r' for reading, and read() reads the entire content to print.
