कथन 1 के लिए उत्तर चुनें.
Choose the answer for statement 1.
import ___________ # statement 1
rec = [ ]
while True:
rn = int(input("Enter"))
nm = input("Enter")
temp = [rn, nm]
rec.append(temp)
ch = input("Enter choice (Y/N)")
if ch.upper == "N":
break
f = open("stud.dat", "____________") #statement 2
__________ .dump(rec, f) #statement 3
_______.close( ) # statement 4
A)
B)
C)
D)
Explanation:
The code involves serializing a list (rec
) into a file. The correct module for serializing and deserializing Python objects into a file is pickle
.
Explanation:
-
Statement 1: To serialize and deserialize objects, we need to import the
pickle
module. -
Statement 2: The file mode should be
"wb"
(write binary) since we are writing serialized data. -
Statement 3: To serialize and save the data to the file, the
pickle.dump()
method is used. -
Statement 4: The file should be closed using
f.close()
.
Correct answer:
(C) pickle