Which statement opens a file in read-only binary mode?

Prepare for the Computer Science (CS) III Exam. Study with multiple choice questions, detailed explanations, and comprehensive resources. Boost your confidence and ace the exam!

The statement that opens a file in read-only binary mode is the one that uses 'rb' as the mode specification. In this context, 'r' stands for reading, and 'b' indicates that the file will be treated as a binary file. This is particularly important for handling non-text files like images or executable files, where data needs to be read as a stream of bytes without any character encoding considerations.

When using 'rb', the file is not only opened for reading but is also treated as a binary file. This means that the data is read as-is, which is crucial for certain applications where preserving the exact byte structure is necessary. The distinction between text mode and binary mode is significant in Python, as text mode could introduce transformations like newline character conversions that do not occur in binary mode.

The other choices involve modes that either do not explicitly signify read-only access or are not set to binary. For instance, 'b+' indicates both reading and writing access, while the 'r+b' mode allows for reading and writing in binary. In contrast, 'b' by itself is not a valid mode and lacks the necessary 'r' for reading. Therefore, the correct choice that identifies opening a file in read-only binary mode is indeed

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy