Test Index

File Handling in Python Get it on Google PlayDownload on the App Store CBSE Board Videos

© examsnet.com
Question : 9 of 37
Marks: +1, -0
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.
[CBSE 2025 Set 4]
Solution:  
Concept:
pickle.dump(obj, file) writes (serialises) an object to a binary file; pickle.load(file) reads it back. The 'rb' mode opens a binary file for reading only.
Explanation:
Assertion: calling dump() on a file opened in 'rb' mode tries to write to a read-only file, so Python raises an error:
io.UnsupportedOperation: write
So (A) is true.
Reason: dump() is used to write, not read (reading is done by load()). So (R) is false.
Answer:
Option C (Assertion (A) is true but, Reason (R) is false.)
© examsnet.com
Advertisements
Go to Question: