Remove a key value pair from dictionary in Python

Deleting Items from a Dictionary

del is a statement we can use to delete item from dictionary.


d = {"server":"A", "database":"master"}    
print d # ww w.  j  a va 2  s .  c  o  m
del d['server']                                 
print d 
d.clear()                                      
print d 

The code above generates the following result.





















Home »
  Python »
    Data Types »




Data Types
String
String Format
Tuple
List
Set
Dictionary