What is pop() method in dictionary | How to use the pop() method of a dictionary.


This method simply removes the specified from the original dictionary, also pop method returns the value so we have to assign it to some variable. This method changes the original dictionary.


X = dictionary.pop(‘key_name’ , ‘Default’)

key_name = Your desired key

Default = Default value if no key is present (Optional)

This method takes a single argument.




Copy code below.

dictionary = {1: ‘Student’,
‘Name’: ‘Waqar Khan’,
‘Age’: 23,
‘Male’: True,
‘Subjects’: ‘Computers’}

x = dictionary.pop(‘Subjects’)


  1. A dictionary with some items is being taken
  2. pop() method is being applied, and since it returns a value, the value is printed inside x.
  3. After the pop() method the original dictionary is printed.


  1. The value inside x is printed.
  2. The original dictionary which was changed is printed.

Interview questions:

  1. Can you remove multiple items with the pop() method?

No, we can only remove a single item from the pop() method.


Waqar Khan

Hello, everyone, I am Waqar Khan. I have done my B.tech in Computer Science. I love to write about Computer Informational blogs. Before write I did proper research on it. Hope you like our blogs. Thank you.

Related Posts

Leave a Reply

Your email address will not be published.