Which of the following functions do you use to write data in binary format?
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.
Related questions:
2025: 14 May Shift 1
2026: 24 May Shift 1
2025: 20 May Shift 1