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.
content = file.[1]()readline() which reads only one line.write() on a file opened for 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]()
write() on a file opened for reading.The close() method properly closes the file to free resources.
Fill both blanks to read all lines from the file into a list.
file = open('data.txt', '[1]') lines = file.[2]() file.close()
read() which returns a string, not a list.Open the file in read mode 'r' and use readlines() to get a list of lines.
Fill all three blanks to read the file content safely using a context manager.
with open('data.txt', '[1]') as file: content = file.[2]() print([3])
Use 'r' mode to read, read() to get content, and print the variable content.
