Which method is used to remove a key-value pair from a dictionary by specifying the key?

  • delete()
  • pop()
  • popitem()
  • remove()
The pop() method is used to remove a key-value pair from a dictionary by specifying the key. It returns the value associated with the key and removes the key-value pair from the dictionary. The del statement can also be used to delete a key-value pair by specifying the key. The popitem() method removes and returns an arbitrary key-value pair, while remove() is not a standard dictionary method.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *