Question 1
Which of the following is NOT one of the four modes for opening a file in Python, using the open() function?
Correct Answer: "d" (delete)
Question 2
The following lines of code will create a new .txt file. What will the file contain?
If the code in question is:
with open('file.txt', 'w') as f:
f.write('Hello World!\n5')
The contents of the file will be:
Correct Answer: Hello World!\n5
(This means the file contains "Hello World!" followed by a newline and then the number 5.)
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 which Python function?
Correct Answer: split()
These answers reflect basic Python file handling and string manipulation concepts.