🧠Python Binary Files – 20 MCQs
-
What is the file mode to open a binary file for reading?
-
A)
'r' -
B)
'rb' -
C)
'wb' -
D)
'ab'👉
-
Which module is used to work with binary files in Python?
-
A)
math -
B)
pickle -
C)
os -
D)
random👉
-
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 👉
-
What does
pickle.load()return?
-
A) A string
-
B) A list
-
C) The original Python object
-
D) A byte stream 👉
-
Which of the following is a binary file extension?
-
A)
.txt -
B)
.csv -
C)
.jpg -
D)
.py👉
-
What is the default protocol used by
pickle.dump()?
-
A) Protocol 0
-
B) Protocol 1
-
C) Protocol 3
-
D) Highest available protocol 👉
-
Which mode appends data to a binary file?
-
A)
'wb' -
B)
'ab' -
C)
'rb' -
D)
'r+'👉
-
What is the data type returned by
f.read()in binary mode?
-
A) String
-
B) List
-
C) Bytes
-
D) Dictionary 👉
-
Which method is used to serialize Python objects?
-
A)
write() -
B)
dump() -
C)
save() -
D)
store()👉
-
What happens if you try to unpickle a corrupted file?
-
A) Returns None
-
B) Raises
FileNotFoundError -
C) Raises
UnpicklingError -
D) Skips the file 👉
-
Which of the following is NOT a valid binary mode?
-
A)
'wb' -
B)
'rb' -
C)
'ab' -
D)
'rbb'👉
-
What does
protocol=0inpickle.dump()signify?
-
A) Latest protocol
-
B) ASCII format
-
C) Oldest protocol
-
D) JSON format 👉
-
Which function is used to open a file in Python?
-
A)
openfile() -
B)
fileopen() -
C)
open() -
D)
readfile()👉
-
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 👉
-
Which method reads all lines from a file?
-
A)
read() -
B)
readline() -
C)
readlines() -
D)
readall()👉
-
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 👉
-
Which method is used to write multiple strings to a file?
-
A)
write() -
B)
writelines() -
C)
dump() -
D)
append()👉
-
What does
fix_imports=Truedo inpickle.dump()?
-
A) Fixes syntax errors
-
B) Ensures compatibility between Python versions
-
C) Imports modules automatically
-
D) Converts text to binary 👉
-
Which file mode allows both reading and writing without erasing data?
-
A)
'w+' -
B)
'r+' -
C)
'wb' -
D)
'rb'👉
-
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
-
What is the file mode to open a binary file for reading?
Show Answer
B) ‘rb’ -
Which module is used to work with binary files in Python?
Show Answer
B) pickle -
What does pickle.dump() do?
Show Answer
B) Writes a Python object to a binary file -
What does pickle.load() return?
Show Answer
C) The original Python object -
Which of the following is a binary file extension?
Show Answer
C) .jpg -
What is the default protocol used by pickle.dump()?
Show Answer
D) Highest available protocol -
Which mode appends data to a binary file?
Show Answer
B) ‘ab’ -
What is the data type returned by f.read() in binary mode?
Show Answer
C) Bytes -
Which method is used to serialize Python objects?
Show Answer
B) dump() -
What happens if you try to unpickle a corrupted file?
Show Answer
C) Raises UnpicklingError -
Which of the following is NOT a valid binary mode?
Show Answer
D) ‘rbb’ -
What does protocol=0 in pickle.dump() signify?
Show Answer
C) Oldest protocol -
Which function is used to open a file in Python?
Show Answer
C) open() -
What does ‘wb’ mode do?
Show Answer
B) Opens file for writing in binary -
Which method reads all lines from a file?
Show Answer
C) readlines() -
What is the purpose of seek() method?
Show Answer
C) To move the file pointer -
Which method is used to write multiple strings to a file?
Show Answer
B) writelines() -
What does fix_imports=True do in pickle.dump()?
Show Answer
B) Ensures compatibility between Python versions -
Which file mode allows both reading and writing without erasing data?
Show Answer
B) ‘r+’ -
What is the output type of pickle.load()?
Show Answer
C) Original Python object
