Q. What will be the output of the following code?

import pickle
ID = {1: "Ziva", 2: "53050", 3: "IT",4: "38",5: "Dunzo"}
fin = open("Emp.pkl","wb")
pickle.dump(EmpID, fin)
fin.close()
fout = open("Emp.pkl", 'rb')
ID = pickle.load(fout)
print( ID [5] )

Answer =

It produces an error that ‘EmpID’ is not defined.

If we modify the code or define the EmpID as ID then:-

import pickle
ID = {1: "Ziva", 2: "53050", 3: "IT",4: "38",5: "Dunzo"}
fin = open("Emp.pkl","wb")
pickle.dump(ID, fin)
fin.close()
fout = open("Emp.pkl", 'rb')
ID = pickle.load(fout)
print( ID [5] )

Output:-

Dunzo
>>>

3 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post