आप या तो अलग-अलग शब्दकोश तत्वों को हटा सकते हैं या किसी शब्दकोश की संपूर्ण सामग्री को साफ़ कर सकते हैं। आप एक ही ऑपरेशन में संपूर्ण शब्दकोश को भी हटा सकते हैं।
संपूर्ण शब्दकोश को स्पष्ट रूप से हटाने के लिए, बस डेल स्टेटमेंट का उपयोग करें।
उदाहरण
निम्नलिखित एक सरल उदाहरण है -
#!/usr/bin/python
dict = {'Name': 'Zara', 'Age': 7, 'Class': 'First'}
del dict['Name']; # remove entry with key 'Name'
dict.clear(); # remove all entries in dict
del dict ; # delete entire dictionary
print "dict['Age']: ", dict['Age']
print "dict['School']: ", dict['School'] आउटपुट
यह निम्नलिखित परिणाम उत्पन्न करता है। ध्यान दें कि एक अपवाद इसलिए उठाया गया है क्योंकि del dict . के बाद शब्दकोश अब मौजूद नहीं है -
dict['Age']: Traceback (most recent call last): File "test.py", line 8, in <module> print "dict['Age']: ", dict['Age']; TypeError: 'type' object is unsubscriptable
नोट - डेल () विधि की चर्चा अगले भाग में की गई है।