Pop from Python Dictionary

.pop() Method in Python

We can use .pop() method to remove key-value pairs from Python dictionary. This method takes a key as an argument and removes it from the dictionary and it returns the value that it removed from the dictionary.

user = {'first_name': 'nishant', 'last_name': 'nigam', 'city': 'Indore'}

user.pop('city')

print(user) # {'first_name': 'nishant', 'last_name': 'nigam'}

Comments

Popular posts from this blog

Inserting and Moving elements inside Ruby Array

Difference between Validations, Callbacks and Observers