Skip to content
Question 71 of 97

Q.Given the following dictionary Day={1:"Monday", 2: "Tuesday", 3: "Wednesday"} Which statement will return "Tuesday".

(a) Day.pop()
(b) Day.pop(2)
(c) Day.pop(1)
(d) Day.pop("Tuesday")
Tripura TbseCBSE Class XII Board 2023MCQ· 1mImportance★★★★★
73% · 71/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 →

The pop() method for dictionaries removes an item by its key and returns the associated value. To return "Tuesday", we need to pop() the key 2. The correct option is (b).

Concept and Intuition

In Python, dictionaries store data as key-value pairs. The pop() method is used to remove a specific key-value pair from a dictionary. Crucially, it returns the value associated with the key that was removed. This is different from methods like del dict[key], which removes the item but doesn't return anything.

The pop() method requires at least one argument: the key of the item you want to remove.

  • If the key exists in the dictionary, pop(key) removes the key-value pair and returns the value.
  • If the key does not exist, pop(key) raises a KeyError.
  • You can also provide a second optional argument, default_value, like pop(key, default_value). If the key is not found, it returns default_value instead of raising a KeyError.
Watch out

For dictionaries, pop() always requires a key as an argument (or a key and a default value). Calling Day.pop() without any arguments will result in a TypeError, unlike list.pop() which removes and returns the last item of a list. This is a common point of confusion.

We are looking for the statement that will return the string "Tuesday". This means we need to identify which option correctly uses pop() to target the key associated with "Tuesday".

Step-by-step Solution

Let's analyze each option given the dictionary Day = {1: "Monday", 2: "Tuesday", 3: "Wednesday"}.

  1. Analyze option (a) Day.pop()

    • This statement attempts to call pop() without any arguments.
    • As explained in the concept, the dictionary pop() method requires a key.
    • Executing Day.pop() will raise a TypeError.
    • Therefore, this statement will not return "Tuesday".
  2. Analyze option (b) Day.pop(2)

    • This statement calls pop() with the argument 2.
    • In our dictionary Day, the key 2 exists, and its corresponding value is "Tuesday".
    • Day.pop(2) will remove the key-value pair (2: "Tuesday") from the dictionary and return the value "Tuesday". …

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.