How to Remove Item with Specified Key Name in Python


In this example we will show how to remove the item with the specified key name using the pop() method in Python.

Source Code

mydict = {
  'name': 'Steven',
  'age': 24,
  'ID': 123456
}

mydict.pop('age')
print(mydict)

Output:

{'name': 'Steven', 'ID': 123456}
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments

How to Remove Item with Specified Key Name in Python


In this example we will show how to remove the item with the specified key name using the del keyword in Python.

Source Code

mydict = {
  'name': 'Steven',
  'age': 24,
  'ID': 123456
}

del mydict['age']
print(mydict)

Output:

{'name': 'Steven', 'ID': 123456}
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments