You develop a Python application for your school. You need to read and write data to a text file. If the file does not exist, it must be created. If the file has content, the content must be removed. Which code should you use?
Suggested Answer:C🗳️
Modes 'r+', 'w+' and 'a+' open the file for updating (reading and writing). Mode 'w+' truncates the file. References: https://docs.python.org/2/library/functions.html https://pythontips.com/2014/01/15/the-open-function-explained/
r+ = Open for reading and writing. The stream is positioned at the beginning of the file.
w+ = Open for reading and writing. The file is created if it does not exist, otherwise it is truncated. The stream is positioned at the beginning of the file.
I think the answer is C.
The correct answer is C, I have used w+ before, r+ does not create a file if it doesn't exist but w+ does. Here's the reference to the website: https://stackoverflow.com/questions/28100993/in-python-why-is-r-but-not-rw-used-to-mean-read-write
This section is not available anymore. Please use the main Exam Page.98-381 Exam Questions
Log in to ExamTopics
Sign in:
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
atxsu
Highly Voted 5 years, 3 months agoprint_HelloWorld
Most Recent 3 years, 1 month agoBillian
4 years, 2 months agosagacious_smith
4 years, 4 months agos_balla_in
5 years, 6 months agohedi12
4 years, 2 months ago