Skip to content
Question 63 of 97

Q.Which of the following statement(s) would give an error after executing the following code? stud={"Murugan":100, "Mithu":95} # Statement 1 print(stud[95]) # Statement 2 Stud["Murugan"]=99 # Statement 3 print(Stud.pop()) # Statement 4 print(Stud) # Statement 5

(a) Statement 2
(b) Statement 3
(c) Statement 4
(d) Statement 2 and 4
Bihar BsebCBSE Class XII Board 2023MCQ· 1mImportance★★★★★
65% · 63/97 Questions
🔒 Locked · start free trial →

You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.

Start your 14-day free trial to unlock the full solution →

A Python dictionary is accessed by its keys, and its pop() method needs the key to remove. print(stud[95]) fails because 95 is a value, not a key (KeyError), and print(Stud.pop()) fails because pop() is called with no key (TypeError). The two error statements are 2 and 4, so the answer is (d).

Understanding the code

stud = {"Murugan": 100, "Mithu": 95}   # Statement 1
print(stud[95])                         # Statement 2
Stud["Murugan"] = 99                    # Statement 3
print(Stud.pop())                       # Statement 4
print(Stud)                             # Statement 5

A dictionary stores key : value pairs. Here the keys are the strings "Murugan" and "Mithu", and the values are 100 and 95.

Why Statement 2 errors

stud[95] tries to use 95 as a key. But 95 is a value in the dictionary, not a key — you cannot look a dictionary up by its value using square brackets. Python therefore raises:

KeyError: 95

Why Statement 4 errors

For a list, pop() can be called with no argument (it removes the last item). For a dictionary, pop() must be told which key to remove, so it needs an argument. Calling it with none raises:

TypeError: pop expected at least 1 argument, got 0

So Statement 4 also errors. …

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.