Skip to main contentSkip to solution

Which of the following functions do you use to write data in binary format?

Solution

✅ Correct Option: 2

The dump() function of the pickle module writes Python objects to a file in binary format. The file must be opened in binary write mode, for example pickle.dump(data, f) with f = open("file.dat", "wb").


Option 1: write() writes text (strings) to a file. It does not convert objects such as lists or dictionaries into binary form.

Option 4: append() is a list method that adds an item to a list. It does not write to a file.

pickle.load() is the reverse of dump(). It reads the binary data back from the file into a Python object.

Keyboard Shortcuts

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