Question:

Assertion (A): For a binary file opened using 'rb' mode,
the pickle.dump() method will display an error.
Reason (R): The pickle.dump() method is used to read from a binary file.

Show Hint

Use pickle.dump() to write,
and pickle.load() to read.
Always match the file mode accordingly.
  • Both Assertion (A) and Reason (R) are true and Reason (R) is the correct explanation for Assertion (A).
  • Both Assertion (A) and Reason (R) are true and Reason (R) is not the correct explanation for Assertion (A).
  • Assertion (A) is true but, Reason (R) is false.
  • Assertion (A) is false but, Reason (R) is true.
Hide Solution
collegedunia
Verified By Collegedunia

The Correct Option is C

Solution and Explanation

The pickle.dump() method is used to write data to a binary file.
It serializes a Python object and writes it to an open binary file in write mode,
commonly opened with 'wb'.
If the file is opened in read-only binary mode ('rb'),
trying to write using pickle.dump() will cause an error,
because the file does not allow writing.
Therefore, Assertion (A) is true.
However, Reason (R) is false because pickle.dump() does not read;
instead, pickle.load() is used to read from a binary file.
Hence, the correct choice is (C).
Was this answer helpful?
0
0

Top Questions on Programming in Python

View More Questions