Skip to main contentSkip to solution

Identify the correct code to read data from the file notes.dat in a binary file:

Solution

✅ Correct Option: 3

Binary files must be opened in binary read mode, "rb". The data is then unpickled with pickle.load(f1), which takes the file object and returns the original Python object. Option 3 does both, then prints and closes the file.


Option 1: mode "r" opens the file in text mode, so pickle.load() fails because it needs a binary stream.

Option 2: file objects have no load() method. load() belongs to the pickle module.

Option 4: f1.read() runs without error but returns raw bytes, not the original object. It does not unpickle the data.

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question