SyntaxStudy
Sign Up
Home Python Reference dict.update() / dict.pop()

dict.update() / dict.pop()

method

update() merges another dict in place; pop() removes and returns the value for a key.

Syntax

dict.update(other) dict.pop(key, default)

Example

python
user = {'name':'Alice','age':28}
user.update({'age':29,'city':'London'})
print(user)  # {'name':'Alice','age':29,'city':'London'}

age = user.pop('age')   # removes 'age', returns 29
phone = user.pop('phone', 'N/A')  # safe with default