🧠 Python Binary Files – 20 MCQs

  1. What is the file mode to open a binary file for reading?

  • A) 'r'

  • B) 'rb'

  • C) 'wb'

  • D) 'ab' 👉

  1. Which module is used to work with binary files in Python?

  • A) math

  • B) pickle

  • C) os

  • D) random 👉

  1. What does pickle.dump() do?

  • A) Reads data from a binary file

  • B) Writes a Python object to a binary file

  • C) Deletes a binary file

  • D) Converts text to binary 👉

  1. What does pickle.load() return?

  • A) A string

  • B) A list

  • C) The original Python object

  • D) A byte stream 👉

  1. Which of the following is a binary file extension?

  • A) .txt

  • B) .csv

  • C) .jpg

  • D) .py 👉

  1. What is the default protocol used by pickle.dump()?

  • A) Protocol 0

  • B) Protocol 1

  • C) Protocol 3

  • D) Highest available protocol 👉

  1. Which mode appends data to a binary file?

  • A) 'wb'

  • B) 'ab'

  • C) 'rb'

  • D) 'r+' 👉

  1. What is the data type returned by f.read() in binary mode?

  • A) String

  • B) List

  • C) Bytes

  • D) Dictionary 👉

  1. Which method is used to serialize Python objects?

  • A) write()

  • B) dump()

  • C) save()

  • D) store() 👉

  1. What happens if you try to unpickle a corrupted file?

  • A) Returns None

  • B) Raises FileNotFoundError

  • C) Raises UnpicklingError

  • D) Skips the file 👉

  1. Which of the following is NOT a valid binary mode?

  • A) 'wb'

  • B) 'rb'

  • C) 'ab'

  • D) 'rbb' 👉

  1. What does protocol=0 in pickle.dump() signify?

  • A) Latest protocol

  • B) ASCII format

  • C) Oldest protocol

  • D) JSON format 👉

  1. Which function is used to open a file in Python?

  • A) openfile()

  • B) fileopen()

  • C) open()

  • D) readfile() 👉

  1. What does 'wb' mode do?

  • A) Opens file for reading

  • B) Opens file for writing in binary

  • C) Opens file for appending

  • D) Opens file for editing 👉

  1. Which method reads all lines from a file?

  • A) read()

  • B) readline()

  • C) readlines()

  • D) readall() 👉

  1. What is the purpose of seek() method?

  • A) To close the file

  • B) To find a word

  • C) To move the file pointer

  • D) To delete content 👉

  1. Which method is used to write multiple strings to a file?

  • A) write()

  • B) writelines()

  • C) dump()

  • D) append() 👉

  1. What does fix_imports=True do in pickle.dump()?

  • A) Fixes syntax errors

  • B) Ensures compatibility between Python versions

  • C) Imports modules automatically

  • D) Converts text to binary 👉

  1. Which file mode allows both reading and writing without erasing data?

  • A) 'w+'

  • B) 'r+'

  • C) 'wb'

  • D) 'rb' 👉

  1. What is the output type of pickle.load()?

  • A) Byte stream

  • B) Pickled object

  • C) Original Python object

  • D) Encoded string 👉

 

Python Binary Files – Class 12 MCQs

  1. What is the file mode to open a binary file for reading?
    Show AnswerB) ‘rb’
  2. Which module is used to work with binary files in Python?
    Show AnswerB) pickle
  3. What does pickle.dump() do?
    Show AnswerB) Writes a Python object to a binary file
  4. What does pickle.load() return?
    Show AnswerC) The original Python object
  5. Which of the following is a binary file extension?
    Show AnswerC) .jpg
  6. What is the default protocol used by pickle.dump()?
    Show AnswerD) Highest available protocol
  7. Which mode appends data to a binary file?
    Show AnswerB) ‘ab’
  8. What is the data type returned by f.read() in binary mode?
    Show AnswerC) Bytes
  9. Which method is used to serialize Python objects?
    Show AnswerB) dump()
  10. What happens if you try to unpickle a corrupted file?
    Show AnswerC) Raises UnpicklingError
  11. Which of the following is NOT a valid binary mode?
    Show AnswerD) ‘rbb’
  12. What does protocol=0 in pickle.dump() signify?
    Show AnswerC) Oldest protocol
  13. Which function is used to open a file in Python?
    Show AnswerC) open()
  14. What does ‘wb’ mode do?
    Show AnswerB) Opens file for writing in binary
  15. Which method reads all lines from a file?
    Show AnswerC) readlines()
  16. What is the purpose of seek() method?
    Show AnswerC) To move the file pointer
  17. Which method is used to write multiple strings to a file?
    Show AnswerB) writelines()
  18. What does fix_imports=True do in pickle.dump()?
    Show AnswerB) Ensures compatibility between Python versions
  19. Which file mode allows both reading and writing without erasing data?
    Show AnswerB) ‘r+’
  20. What is the output type of pickle.load()?
    Show AnswerC) Original Python object
error: Content is protected !!