Practice More Questions From: Quiz 8 – File I/O
Q:
What does the following code do? f = open(“test.txt”)
Q:
What does the following code do? f = open(“test.txt”, “r+”)
Q:
What will happen if you run the following code, but “test.txt” does not exist? f = open(“test.txt”, “a”) </pre.
Q:
Which of the following commands can be used to read all of the content in a file object f as a string?
Q:
What is the result of the following code? lst = [] with open(“text.txt”, “r”) as f: lines = f.readlines() for i in range(2): lst.append(lines[i].rstrip()) print(lst) If we have a file “text.txt” with the following content?
Q:
What is the result of the following code? with open(“text.txt”, “w”) as f_write: f_write.write(“That is the wisdom of life.”) with open(“text.txt”, “r”) as f_read: line = f_read.readline() print(line) If we have a file “text.txt” with following content?
Subscribe
0 Comments