Exercise: Reading And Writing Files

Questions for: Reading And Writing Files

How can you open a file named "example.txt" in Python for reading?
A:
open("example.txt", "w")
B:
open("example.txt", "r")
C:
open("example.txt", "a")
D:
open("example.txt", "x")
Answer: B
To open a file for reading, you should use the mode "r" in the open() function.
Ad Slot (Above Pagination)
Quiz