CBSE Class 12 Computer Science
Question 116 of 145
File Handling — Question 12
Back to all questions 12
Question What will be the output of the following code ?
import pickle
List1 = ['Roza', {'a': 23, 'b': True}, (1, 2, 3), [['dogs', 'cats'], None]]
List2 = ['Rita', {'x': 45, 'y': False}, (9, 5, 3), [['insects', 'bees'], None]]
with open('data.pkl', 'wb') as f:
f.write(List1)
with open('data.pkl', 'wb') as f:
f.write(List2)
with open('data.pkl', 'rb') as f:
List1 = pickle.load(f)
print(List1)The code raises an error because write() function does not work in binary file. To write an object on to a binary file dump() function of pickle module is used.