1.

Which of the following are the modes of both writing and reading in binary format in file?(a) wb+(b) w(c) wb(d) w+This question was posed to me in an interview for internship.The question is from Files topic in portion Regular Expressions and Files of Python

Answer»

The correct CHOICE is (a) wb+

For explanation: Here is the description below

“w”Opens a file for writing only. Overwrites the file if the file EXISTS. If the file does not exist, CREATES a new file for writing.

“wb” Opens a file for writing only in binary FORMAT. Overwrites the file if the file exists. If the file does not exist, creates a new file for writing.

“w+” Opens a file for both writing and reading. Overwrites the EXISTING file if the file exists. If the file does not exist, creates a new file for reading and writing.

“wb+” Opens a file for both writing and reading in binary format. Overwrites the existing file if the file exists. If the file does not exist, creates a new file for reading and writing.



Discussion

No Comment Found

Related InterviewSolutions