Question 1
The option that is NOT one of the four modes for opening a file in Python using the open()
function is:
- "d" (delete)
The valid modes are:
- "r" (read)
- "w" (write)
- "a" (append)
Question 2
The following lines of code will create a new .txt file. If the code looks similar to this:
with open('file.txt', 'w') as f:
f.write("Hello World!\n5")
The file will contain:
- Hello World! (followed by a newline)
- 5
So, the correct response would be:
- Hello World! \n5
Question 3
If we wanted to separate parts of a text file using a specified parameter and put them in a list, we might use the following Python function:
- split()
The split()
method allows you to break a string into a list based on a specified delimiter.
Here are the answers summarized:
- d (delete)
- Hello World! \n5
- split()